-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsqlquery4.sql
49 lines (44 loc) · 1.71 KB
/
sqlquery4.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
38
39
40
41
42
43
44
45
46
47
48
49
Problem Statement:
Write a SQL query to print the item name, item type and price of all the items present in both the shops in descending order of their price.
Information about the table:
Table shop_1:
+---------+------------+------------+-------+
| item_id | item_name | item_type | price |
+---------+------------+------------+-------+
| 1 | pencil | stationery | 10 |
| 2 | soap | toiletries | 25 |
| 3 | eraser | stationery | 5 |
| 4 | toothbrush | toiletries | 30 |
| 5 | toothpaste | toiletries | 50 |
+---------+------------+------------+-------+
Table shop_2:
+---------+------------+------------+-------+
| item_id | item_name | item_type | price |
+---------+------------+------------+-------+
| 1 | facewash | toiletries | 70 |
| 2 | soap | toiletries | 25 |
| 3 | pencil | stationery | 15 |
| 4 | paintbrush | stationery | 30 |
| 5 | shampoo | toiletries | 100 |
+---------+------------+------------+-------+
Note: Write keywords of syntax in uppercase alphabets.
Solution:
SELECT item_name, item_type, price FROM shop_1
UNION ALL
SELECT item_name, item_type, price FROM shop_2
ORDER BY PRICE desc;
Output:
+------------+------------+-------+
| item_name | item_type | price |
+------------+------------+-------+
| shampoo | toiletries | 100 |
| facewash | toiletries | 70 |
| toothpaste | toiletries | 50 |
| toothbrush | toiletries | 30 |
| paintbrush | stationery | 30 |
| soap | toiletries | 25 |
| soap | toiletries | 25 |
| pencil | stationery | 15 |
| pencil | stationery | 10 |
| eraser | stationery | 5 |
+------------+------------+-------+