SQL WHERE Clause

WHERE clause is used to filter records, and extract only the specific data that we want in any special case.

Operators of WHERE Clause

Below are operators that could be used with where clause in SQL.

Operator Description
= Equal
< > Not equal its is some time is used as !
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
BETWEEN Between a certain range
LIKE Search for a pattern
IN To specify multiple possible values for a column

Basic Syntax

SELECT statement can be used to select single column from a database.

Let’s assume we have a table named as customers and this table having multiple columns like customer_name, customer_address, customer_contact_no. We want to select all the data of customer the above select statement will be utilized.

<?php  

	SELECT column1, column2....columnN
	FROM table_name
	WHERE condition;

?>

Examples

Select all the customers who belongs to Pakistan.

<?php  

	SELECT * FROM Customers
	WHERE Country='pakistan';

?>


Select a customer by ID.

<?php  

	SELECT * FROM Customers
	WHERE CustomerID=20;

?>