diff --git a/setoperations/sqlquery10.sql b/setoperations/sqlquery10.sql new file mode 100644 index 0000000..e099a06 --- /dev/null +++ b/setoperations/sqlquery10.sql @@ -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 | ++------------+------------+ \ No newline at end of file diff --git a/setoperations/sqlquery11.sql b/setoperations/sqlquery11.sql new file mode 100644 index 0000000..f0cfec0 --- /dev/null +++ b/setoperations/sqlquery11.sql @@ -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 | ++-----------+-------+ \ No newline at end of file diff --git a/setoperations/sqlquery6.sql b/setoperations/sqlquery6.sql new file mode 100644 index 0000000..2afbbd6 --- /dev/null +++ b/setoperations/sqlquery6.sql @@ -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 | ++---------+----------+----------+---------+ \ No newline at end of file diff --git a/setoperations/sqlquery7.sql b/setoperations/sqlquery7.sql new file mode 100644 index 0000000..39c2587 --- /dev/null +++ b/setoperations/sqlquery7.sql @@ -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 | ++-----------+------------+ \ No newline at end of file diff --git a/setoperations/sqlquery8.sql b/setoperations/sqlquery8.sql new file mode 100644 index 0000000..f62d50b --- /dev/null +++ b/setoperations/sqlquery8.sql @@ -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 | ++-----------+-------+ diff --git a/setoperations/sqlquery9.sql b/setoperations/sqlquery9.sql new file mode 100644 index 0000000..585b123 --- /dev/null +++ b/setoperations/sqlquery9.sql @@ -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 | ++---------+----------+----------+-------------------+