Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
0
1
00:00:01,970 --> 00:00:04,480
Next, we are going to discuss the union operator.
1
2
00:00:05,670 --> 00:00:10,230
Union operator combines the result sets of two or more select statement.
2
3
00:00:11,150 --> 00:00:18,350
So in except we saw that it is giving us the ResultSet of one table, and from that it removed
3
4
00:00:18,350 --> 00:00:24,710
the result set of other table. union is combining both of these ResultSet and while combining
4
5
00:00:24,710 --> 00:00:28,690
the duplicate rows from both, the result sets will be removed.
5
6
00:00:28,790 --> 00:00:31,740
So it will be similar to the select distinct.
6
7
00:00:32,540 --> 00:00:39,740
So the syntax for this union operators, you select the expressions that you want from table one, you
7
8
00:00:39,740 --> 00:00:41,340
can specify where conditions also.
8
9
00:00:42,320 --> 00:00:50,000
Then you write union, just like we wrote, except then you specify the second select condition with expressions.
9
10
00:00:51,130 --> 00:00:56,880
One thing to note here is for expression 1 in the first statement and expression 1 in the second
10
11
00:00:57,100 --> 00:00:57,640
statement.
11
12
00:00:59,110 --> 00:01:05,710
These two should have the same data types if expression, one in first selected statement is integer then it should be
12
13
00:01:05,710 --> 00:01:06,010
integer
13
14
00:01:06,010 --> 00:01:13,720
in the second select statement also and the number of expressions in the first select statement, if it is n
14
15
00:01:13,720 --> 00:01:15,010
here, it should be.
15
16
00:01:15,010 --> 00:01:22,210
n in the second select statement also. you can specify more than two select statements using multiple
16
17
00:01:22,210 --> 00:01:22,670
unions.
17
18
00:01:23,230 --> 00:01:24,460
Let us look at an example.
18
19
00:01:27,220 --> 00:01:32,860
Suppose you want to find out all the customer ideas that you have in your database, either they are
19
20
00:01:32,860 --> 00:01:37,050
present in the sales table or they are present in the customer table.
20
21
00:01:38,770 --> 00:01:47,150
To do that, to get that combined customer ID table, we will use the union operator will write select customer
21
22
00:01:47,150 --> 00:01:48,760
Id from sales table.
22
23
00:01:49,690 --> 00:01:55,940
And Union select customer id from customer table, and we will order this by the customer id.
23
24
00:01:56,110 --> 00:02:03,190
Let's go right this so select customer id from sales table
24
25
00:02:10,240 --> 00:02:12,760
union select customer id from customer table
25
26
00:02:20,020 --> 00:02:21,190
order by customer Id.
26
27
00:02:24,600 --> 00:02:35,010
Just compare that this is exactly same as the except query that we wrote just that except it replaced
27
28
00:02:35,010 --> 00:02:37,440
by Union. Let us run this query
28
29
00:02:40,440 --> 00:02:47,580
You can see 10315, which is not president in the customer table is present in our ResultSet,
29
30
00:02:47,910 --> 00:02:49,980
10375 is part of both.
30
31
00:02:50,250 --> 00:02:56,480
And it is President in the ResultSet, 10480 which is not part of sales table, is present in this result set
31
32
00:02:57,210 --> 00:03:05,490
So basically, all the customer ids are present in our result set. This is how we use union and this completes the
32
33
00:03:05,520 --> 00:03:08,790
joins and other table combination operators.
3572
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.