Skip to content

Commit

Permalink
added all sql queries
Browse files Browse the repository at this point in the history
  • Loading branch information
thatsabhishek committed Apr 17, 2023
1 parent 5c50b2a commit 4990440
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 0 deletions.
42 changes: 42 additions & 0 deletions setoperations/sqlquery10.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Problem Statement:
Write a SQL query to print the item name, item type of only the items which are available in shop 1 but not in shop 2 in the ascending order of item name.

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 FROM shop_1 LEFT JOIN shop_2
USING(item_name, item_type)
WHERE shop_2.item_id IS NULL
ORDER BY item_name;

Output:
+------------+------------+
| item_name | item_type |
+------------+------------+
| eraser | stationery |
| toothbrush | toiletries |
| toothpaste | toiletries |
+------------+------------+
40 changes: 40 additions & 0 deletions setoperations/sqlquery11.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Problem Statement:
Write a SQL query to print the item name, price of only the items which are available in shop 2 but not in shop 1 whose price is greater than 50.

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, price FROM shop_1 RIGHT JOIN shop_2
USING(item_name, price)
WHERE shop_2.price>50;

Output:
+-----------+-------+
| item_name | price |
+-----------+-------+
| facewash | 70 |
| shampoo | 100 |
+-----------+-------+
36 changes: 36 additions & 0 deletions setoperations/sqlquery6.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Problem Statement:
Find out all the details of employees that work for both the departments.

Information about the table:
Table Empdept1:
+---------+----------+----------+-------------------+
| EmpCode | EmpFName | EmpLName | Job |
+---------+----------+----------+-------------------+
| 9369 | TONY | STARK | SOFTWARE ENGINEER |
| 9499 | TIM | ADOLF | SALESMAN |
| 9566 | KIM | JARVIS | MANAGER |
| 9654 | SAM | MILES | SALESMAN |
+---------+----------+----------+-------------------+

Table Empdept2:
+---------+----------+----------+----------+
| EmpCode | EmpFName | EmpLName | Job |
+---------+----------+----------+----------+
| 9566 | KIM | JARVIS | MANAGER |
| 9902 | ANDREW | FAULKNER | ANALYST |
| 9685 | SAMAY | DAGA | SALESMAN |
+---------+----------+----------+----------+

Note-1: The data should not contain duplicate rows of employees.
Note-2: Write keywords of syntax in uppercase alphabets.

Solution:
SELECT DISTINCT * FROM empdept1 INNER JOIN empdept2
USING (empcode, empfname, emplname, job);

Output:
+---------+----------+----------+---------+
| EmpCode | EmpFName | EmpLName | Job |
+---------+----------+----------+---------+
| 9566 | KIM | JARVIS | MANAGER |
+---------+----------+----------+---------+
38 changes: 38 additions & 0 deletions setoperations/sqlquery7.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Problem Statement:
Write a SQL query to find the item name along with its type of stationery item which is available in both the shops.

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 DISTINCT item_name, item_type FROM shop_1 INNER JOIN shop_2
USING (item_name, item_type) WHERE item_type = 'stationery';

Output:
+-----------+------------+
| item_name | item_type |
+-----------+------------+
| pencil | stationery |
+-----------+------------+
38 changes: 38 additions & 0 deletions setoperations/sqlquery8.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Problem Statement:
Write a SQL query to find the name and price of items whose price is greater than 20 and available in both the shops.

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 DISTINCT item_name, price FROM shop_1 INNER JOIN shop_2
USING(item_name, price) WHERE price >20;

Output:
+-----------+-------+
| item_name | price |
+-----------+-------+
| soap | 25 |
+-----------+-------+
38 changes: 38 additions & 0 deletions setoperations/sqlquery9.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Problem Statement:
List down all the details of employees working in dept1 but not in Dept2.

Information about the table:
Table Empdept1:
+---------+----------+----------+-------------------+
| EmpCode | EmpFName | EmpLName | Job |
+---------+----------+----------+-------------------+
| 9369 | TONY | STARK | SOFTWARE ENGINEER |
| 9499 | TIM | ADOLF | SALESMAN |
| 9566 | KIM | JARVIS | MANAGER |
| 9654 | SAM | MILES | SALESMAN |
+---------+----------+----------+-------------------+

Table Empdept2:
+---------+----------+----------+----------+
| EmpCode | EmpFName | EmpLName | Job |
+---------+----------+----------+----------+
| 9566 | KIM | JARVIS | MANAGER |
| 9902 | ANDREW | FAULKNER | ANALYST |
| 9685 | SAMAY | DAGA | SALESMAN |
+---------+----------+----------+----------+

Note: Write keywords of syntax in uppercase alphabets.

Solution:
SELECT * FROM empdept1 LEFT JOIN empdept2
USING (empcode, empfname, emplname, job)
WHERE empdept2.empcode IS NULL;

Output:
+---------+----------+----------+-------------------+
| EmpCode | EmpFName | EmpLName | Job |
+---------+----------+----------+-------------------+
| 9369 | TONY | STARK | SOFTWARE ENGINEER |
| 9499 | TIM | ADOLF | SALESMAN |
| 9654 | SAM | MILES | SALESMAN |
+---------+----------+----------+-------------------+

0 comments on commit 4990440

Please sign in to comment.