SQL where
SQL Tutorial » SQL where
SQL "WHERE" (without quotes) clause is used to filter rows and to extract only those records from SQL database that fulfill a specified condition.
Also WHERE is used in the UPDATE, DELETE statement, etc.,
Syntax:
FROM table_name
WHERE condition;
Let's look at the "Users" table: We will have six columns as: "id", "first_name", "country", "user_name", "email" and "reg_date":
ID | First Name | Last Name | Country | |
---|---|---|---|---|
1 | Clark | Kent | USA | clarkkent@mail.com |
2 | Pire | Joveau | France | pierej@mail.com |
3 | Nicky | Anderson | USA | nickya@mail.com |
4 | Pepe | Martínez | Spain | martinezpeper@mail.com |
5 | Peter | Parker | SUA | peterparker@mail.com |
SQL where
In the next examples we display people from USA from "Users" table using WHERE clause:
WHERE Country='USA';
Output displayed:
ID | First Name | Last Name | Country | |
---|---|---|---|---|
1 | Clark | Kent | USA | clarkkent@mail.com |
3 | Nicky | Anderson | USA | nickya@mail.com |
5 | Peter | Parker | SUA | peterparker@mail.com |
Related subjects:
How to create database phpmyadmin?
Insert multiple rows
PHP select / view data
Conect to MySQLi
PHP MySQLi create table
Tags: sql where, multiple conditions, where clause, where date, where in list, not in, where not null, between,update sql, What is the use of where in SQL?, What is == in SQL?, What are the SQL clauses?
WHERE clause with Text Fields vs. Numeric Fields
As we saw in the previous example SQL requires single quotes around text values, but also allow double quotes most database systems.
In the next example, numeric fields should not be enclosed in quotes:
WHERE ID=4;
Output displayed:
ID | First Name | Last Name | Country | |
---|---|---|---|---|
4 | Pepe | Martínez | Spain | martinezpeper@mail.com |
WHERE Clause Operators In the SQL
WHERE Clause Operators In the SQL - WHERE clause the following operators can be used:
- = Equal
- < Less than
- > Greater than
- <= Less than or equal
- >= Greater than or equal
- <> Not equal. Operator may be written as !=
- LIKE Search for a pattern
- BETWEEN Between a certain range
- IN Specify multiple possible values for a column
sql where, multiple conditions, where clause, where date, where in list, not in, where not null, between,update sql, What is the use of where in SQL?, What is == in SQL?, What are the SQL clauses?
SQL where clause - sql tutorial
This tool makes it easy to create, adjust, and experiment with custom colors for the web.

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.

Find here examples of creative and unique website layouts.

Find here examples of creative and unique website CSS HTML menu.