You are on page 1of 2

SQL Queries for Practice

Q:1 Consider the following table “Product” and write the queries for
the following:
S_No P_Name Qty Cost City
S1 Biscuit 120 12 Delhi
S2 Bread 200 25 Mumbai
S3 Chocolate 350 40 Mumbai
S4 Sauce 400 45 Chennai
S5 Jam 250 30 Delhi

1. Write a SQL command to display the records in descending order


by S_No.

Ans: Select * from Product order by S_No desc;

2. Display P_Name, Cost and City for all the products whose Qty is
less than 300.

Ans: Select P_Name, Cost, City from Product where Qty<300;

3. Display all the records alphabetically by P_Name.

Ans: Select * from Product order by P_Name;

4. Display all Products whose Qty is between 100 and 400.

Ans: Select * from Product where Qty between 100 and 400;
5. Display S_No and P_Name of all the products located in Delhi.

Ans: Select S_No, P_Name from Product where City=’Delhi’;

6. Display the data for all products sorted by their quantity.


Ans: Select * from Product order by Qty;

7. Change the Qty of the product – ‘Bread’ to 275.


Ans: Update Product set Qty=275 where P_Name=’Bread’;

8. Display the Product name and total cost for all the products in the
Product table.
Ans: Select P_Name, Cost*Qty “Total Cost” from Product;

You might also like