SQL Queries and Operators [Week 7]
SELECT and Filtering Data
-
SELECT: Retrieve data from a table.
SELECT column_name FROM table_name; -
DISTINCT: Retrieve unique records.
SELECT DISTINCT column_name FROM table_name; -
WHERE: Filter records based on a condition.
SELECT * FROM table_name WHERE condition; -
LIKE: Search for a specified pattern in a column.
SELECT * FROM table_name WHERE column_name LIKE '%pattern%'; -
ORDER BY: Sort the result-set.
SELECT * FROM table_name ORDER BY column_name ASC|DESC; -
LIMIT/TOP: Limit the number of records returned
SELECT * FROM table_name LIMIT number;
Logical Operators
-
AND, OR, NOT: Combine multiple conditions in the WHERE clause.
SELECT * FROM table_name WHERE condition1 AND condition2; -
IN: Match against multiple values.
SELECT * FROM table_name WHERE column_name IN ('value1', 'value2'); -
BETWEEN: Filter a range of values.
SELECT * FROM table_name WHERE column_name BETWEEN value1 AND value2;