Logo

K-Learn

SQL Where Clause

< Previous Next >

The WHERE clause in SQL is used to filter the rows that are returned in a query. It allows us to specify a condition that must be met for a row to be included in the result set.

Where Syntax

SELECT column1, column2, …
FROM table_name
WHERE condition;

Here's an example:

Let's say we have a table named "student" with columns "id", "name", "email", "phone", and "address". We can use the WHERE clause to filter the rows that are returned. For example, to retrieve only the rows where the "name" column is "John Doe",

We would use the following statement:

SELECT * FROM student WHERE name = 'John Doe';

OUTPUT

To filter rows based on conditions such as greater than, less than, or not equal to,

We can also use comparison operators in the WHERE clause to filter rows based on conditions such as greater than, less than, or not equal to. For example, to retrieve only the rows where the "id" column is greater than 2,

We would use the following statement:

SELECT * FROM student WHERE id > 2;

OUTPUT


< Previous Next >