Informatics Practices
In a database there are two tables "Product" and "Client" as shown below :
Table : Product
| P_ID | ProductName | Manufacture | Price |
|---|---|---|---|
| P001 | Moisturiser | XYZ | 40 |
| P002 | Sanitizer | LAC | 35 |
| P003 | Bath Soap | COP | 25 |
| P004 | Shampoo | TAP | 95 |
| P005 | Lens Solution | COP | 350 |
Table : Client
| C_ID | ClientName | City | P_ID |
|---|---|---|---|
| 01 | Dreamz Disney | New Delhi | P002 |
| 05 | Life Line Inc | Mumbai | P005 |
| 12 | 98.4 | New Delhi | P001 |
| 15 | Appolo | Banglore | P003 |
Write the commands in SQL queries for the following :
(i) To display the details of Product whose Price is in the range of 40 and 120 (Both values included).
(ii) To display the ClientName, City from table Client and ProductName and Price from table Product, with their corresponding matching P_ID.
(iii) To increase the Price of all the Products by 20.
SQL Joins & Grouping
4 Likes
Answer
(i)
SELECT *
FROM PRODUCT
WHERE PRICE BETWEEN 40 AND 120;
Output
+------+-------------+--------------+-------+
| P_ID | ProductName | Manufacturer | Price |
+------+-------------+--------------+-------+
| P001 | MOISTURISER | XYZ | 40 |
| P004 | SHAMPOO | TAP | 95 |
+------+-------------+--------------+-------+
(ii)
SELECT C.CLIENTNAME, C.CITY, P.PRODUCTNAME, P.PRICE
FROM CLIENT C, PRODUCT P
WHERE C.P_ID = P.P_ID;
Output
+---------------+-----------+---------------+-------+
| CLIENTNAME | CITY | PRODUCTNAME | PRICE |
+---------------+-----------+---------------+-------+
| DREAMZ DISNEY | NEW DELHI | SANITIZER | 35 |
| LIFE LINE INC | MUMBAI | LENS SOLUTION | 350 |
| 98.4 | NEW DELHI | MOISTURISER | 40 |
| APPOLO | BANGALORE | BATH SOAP | 25 |
+---------------+-----------+---------------+-------+
(iii)
UPDATE PRODUCT
SET PRICE = PRICE + 20;
Answered By
1 Like
Related Questions
How is a cross join different from natural join ? Give example.
A table "TRAINS" in a database has degree 3 and cardinality 8. What is the number of rows and columns in it ?
In a Database School there are two tables Member and Division as shown below.
Table : Member
EmpId Name Pay Divno 1001 Shankhya 34000 10 1003 Ridhima 32000 50 1002 Sunish 45000 20 Table : Division
Divno Divname Location 10 Media TF02 20 Dance FF02 30 Production SF01 (i) Identify the foreign key in the table Member.
(ii) What output, you will get, when an equi-join query is executed to get the NAME from Member Table and corresponding from Division table ?
Consider following tables to answer below question :
Salesman (salesman_id, name, city, commission ) and Customer (customer_id, cust_name, city, grade, salesman_id )Write an SQL query to display all salesmen and customer located in Chennai.