SQL Tutorial



FILTERING IN SQL


๐ŸŽฏ Filtering Data in SQL

Filtering helps you narrow down your query results by including only rows that meet specific criteria. This is done using the WHERE clause.

๐Ÿ“˜ Syntax:
SELECT column1, column2, ...
FROM table_name
WHERE condition;

๐Ÿงช Example: Get Students Who Scored Above 80

SELECT name, marks
FROM Students
WHERE marks > 80;
  

This query filters out students whose marks are above 80.


๐ŸŽฎ Try It Yourself

Hereโ€™s a sample table named Products:

ProductID Name Category Price
101LaptopElectronics55000
102MobileElectronics30000
103ChairFurniture1500
104TableFurniture2500

๐Ÿงฉ Your Task: Write a query to show only those products whose category is Furniture and price is above 2000.


๐Ÿ” Common Operators for Filtering

  • = : Equal to
  • >, < : Greater than / Less than
  • >=, <= : Greater or equal / Less or equal
  • != or <> : Not equal to
  • AND, OR : Combine multiple conditions
  • IN, NOT IN : Match any (or none) in a list
  • LIKE : Match a pattern (e.g., 'A%' for names starting with A)

๐ŸŽฒ Bonus Challenge

Write a query to fetch employees from the Employees table who:

  • Have a salary more than 40,000
  • AND belong to the "Sales" department
โœ๏ธ Try this query on your local database or any online SQL playground!

๐Ÿ“Œ Summary

  • Use the WHERE clause to filter records.
  • Combine filters with AND, OR, NOT.
  • Use LIKE or IN for more flexible matching.

Next Topic โžก๏ธ: Learn how to filter using BETWEEN and LIKE to handle ranges and patterns!


๐ŸŒŸ Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review