File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ -- nested query
2
+ -- select all salesPerson with company RED
3
+ -- select all salesPerson from SalesPerson not in the above table
1
4
5
+ select sp .name
6
+ from SalesPerson sp
7
+ where sales_id not in
8
+ (select o .sales_id
9
+ from Orders o
10
+ where o .com_id in
11
+ (select c .com_id
12
+ from Company c
13
+ where c .name = ' RED' ))
14
+
15
+ -- ----------------------------------------------------------------------------------------------------------------------------------------------
16
+ -- JOIN Company c and Ordered o
17
+ -- pick all sales_id with company = 'RED'
18
+ -- pick all salesPerson from SalesPerson not in temp table above
19
+
20
+ select sp .name
21
+ from SalesPerson sp
22
+ where sales_id not in
23
+ (select o .sales_id
24
+ from Orders o
25
+ inner join Company c
26
+ on c .com_id = o .com_id
27
+ where c .name = ' RED' )
28
+
29
+
30
+ -- no companies listed
You can’t perform that action at this time.
0 commit comments