-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQL Server Left Join.sql
More file actions
44 lines (40 loc) · 969 Bytes
/
Copy pathSQL Server Left Join.sql
File metadata and controls
44 lines (40 loc) · 969 Bytes
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
38
39
40
41
42
43
44
SELECT
product_name,
order_id
FROM production.products p
LEFT JOIN sales.order_items o ON o.product_id = p.product_id
ORDER BY order_id;
GO
SELECT
[product_name],
[order_id]
FROM production.products AS p
LEFT JOIN sales.order_items AS o ON o.product_id = p.product_id
WHERE [order_id] IS NULL;
GO
SELECT
p.product_name,
o.order_id,
i.item_id,
o.order_date
FROM production.products p
LEFT JOIN sales.order_items i ON i.product_id = p.product_id
LEFT JOIN sales.orders o ON o.order_id = i.order_id
ORDER BY order_id;
GO
SELECT
product_name,
order_id
FROM production.products p
LEFT JOIN sales.order_items o ON o.product_id = p.product_id
WHERE order_id = 100
ORDER BY order_id;
GO
SELECT
p.product_id,
product_name,
order_id
FROM production.products p
LEFT JOIN sales.order_items o ON O.product_id = p.product_id AND o.order_id = 100
ORDER BY order_id DESC;
GO