Select WHERE clause:

When you want to conditionally select data from a table, a WHERE clause can be added to the SELECT statement.

Syntax:

SELECT column_name FROM table_name WHERE column operator value

Operator:

Here is the list of operators that will be used.

Operator Description
= Equal
<> Not equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
BETWEEN Between an inclusive range
LIKE Search for a pattern
IN If you know the exact value you want to return for at least one of the columns

 

Example:

Using UserInfo Table

LastName FirstName Address City Year
Hansen Ola Timoteivn 10 Sandnes 1951
Svendson Tove Borgvn 23 Sandnes 1978
Svendson Stale Kaivn 18 Sandnes 1980
Pettersen Kari Storgt 20 Stavanger 1960

Query:
SELECT * FROM UserInfo WHERE City = “Sandnes”

The Result:

LastName FirstName Address City Year
Hansen Ola Timoteivn 10 Sandnes 1951
Svendson Tove Borgvn 23 Sandnes 1978
Svendson Stale Kaivn 18 Sandnes 1980

 

Leave a Reply

Your email address will not be published. Required fields are marked *