-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubquery_and_join.sql
37 lines (32 loc) · 968 Bytes
/
Subquery_and_join.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Select *
From W3schoolsDB.Products
Where Price Between 10 And 19 ; -- inclusive
Select *
From W3schoolsDB.Customers
Where Country In ("UK", "Canada") ;
-- Old fashion Join
Select c.CustomerID, o.CustomerID, c.Country, o.OrderDate
From W3schoolsDB.Customers As c, W3schoolsDB.Orders As o
Where c.CustomerID = o.CustomerID ;
-- Newer Join
Select c.CustomerID, o.CustomerID, c.Country, o.OrderDate
From W3schoolsDB.Customers As c
Right Join W3schoolsDB.Orders As o
On c.CustomerID = o.CustomerID
Where c.Country = "UK";
Select *
From W3schoolsDB.Employees As e
Inner Join W3schoolsDB.Orders As o
On e.EmployeeID = o.EmployeeID
Inner Join W3schoolsDB.Customers As c
On o.CustomerID = c.CustomerID
Where e.FirstName="Andrew" and e.LastName="Fuller" ;
-- Subquery
Select *
From W3schoolsDB.Orders
Where CustomerID In
(
Select CustomerID /*select _ _ from inside sub-query has to be same for outside where _ _*/
From W3schoolsDB.Customers
Where Country = "UK"
) ;