Basic SQL Queries example

 Basics SQL Query

From the below table - table name - Product


Product_ID Product_Name Product_Price Product_Category Expiry
1 Cumin Powder 100 Kitechen - Spices 2023-07-18
2 Turmeric Powder 75 Kitechen - Spices 2023-08-15
3 Coriander Powder 55 Kitechen - Spices 2023-09-01
4 Bathing Soap 35 Personal - Care 2023-10-15
5 Hair Conditionar 100 Personal - Care 2023-12-30
6 Face Wash 65 Personal - Care 2023-11-19
7 Tooth Paste 75 Personal - Care 2023-10-18

Queries using top and order by clause

  • List the top 3 products based on price higher to lower.
  • List bottom 2 products based on price higher to lower.
  • List the product details that expires before all other product.
  • List the product details that expires at last.
  • List top 5 product with their names sorted on alphabetical order.

Queries using where clause

  • List the product details which belongs to Kitchen - Spices category
  • List the products which are expiring after 2023-08-01.
  • List the products whose price is below 70.
  • List the product which costs between 60-80.
  • List the product which are either Kitchen - Spices or Price is greater than 60.

Queries on wildcard search

  • List the products whose name start with "C" and ends with "R".
  • List the product whose name contains "Pow"

More Questions will be added soon, please write in the comment box if this is helpful or you are not able to solve any query.

No comments:

Post a Comment

T-SQL LEAD LAG and SUM function based query

  Query on T-SQL window clause Below is the sales table Order_Date Name Product SubCategory ...