SQL Where clause is used to filter records in a database table, allowing you to retrieve only the rows that meet specific conditions.
SQL Where Syntax
SELECT column1, column2, ... FROM table_name WHERE condition;
SQL Where Examples
SQL Where Filtering by a Single Condition Example
This query retieves all columns from the students table for rows where the NAME starts with the letter ‘A’.
SELECT * FROM Students WHERE name LIKE 'A%';
SQL Where Combining Multiple Conditions with AND
This query retrieves all columns from the PATIENTS table for rows where the gender is ‘M’ (male) and the contact_number is not NULL.
SELECT * FROM Patients WHERE gender = 'M' AND contact_number IS NOT NULL;
SQL Where Using OR to Broade the Search
This query retrieves all columns from the DOCTORS table for rows where the specialty is either ‘Cardiology’ or ‘Neurology’.
SELECT * FROM Doctors WHERE specialty = 'Cardiology' OR specialty = 'Neurology';