SQL where clause

The SQL where clause is used to extract data like a filter. The SQL where statement works according to your specified condition. The data gets filtered according to the condition you put through the where clause.

Related: 20 best examples of SQL like operator

You can use any type of value inside a “where statement” like alphabet and numbers. Let us know how to use SQL where clause.

/ ***** That record will come, where will be ABC name ***** /

SELECT * FROM Employees
WHERE name='abc';


/ ***** That record will come, where salary will be 2000 ***** /

SELECT * FROM Employees
WHERE salary=2000;


/ ***** Those names will come whose age is 50 ***** /

SELECT name FROM Employees
WHERE age=50;


/ ***** His join date will be named as klm ***** /

SELECT joinDate FROM Employees
WHERE name='klm';


/ ***** His salary will come, which will be named tuv ***** /

SELECT salary FROM Employees
WHERE name='tuv';


/ ***** Their records will come, whose age is above 30 ***** /

SELECT * FROM Employees
WHERE age >=30;


/ ***** Their records will come, whose age is below 50 ***** /

SELECT * FROM Employees
WHERE age <=50;
EmployeeIDNameAgeSalaryJoinDate
1abc20200019-2-2020
2efg30540010-2-2019
3hij40560016-4-20015
4klm50360010-5-2004
5nop60240015-2-2009
6qrs70570010-6-2018
7tuv80800025-12-2016
8wxy90980010-7-2005
9zzz100520030-9-2014

SQL Where And

If you want to apply more than one condition, then for that you have to use AND operator. But keep in mind that this statement will work only if both of your conditions are correct. Let’s know how to use “where and statement”.

/ ***** The record whose age is 50, and salary is 5400 ***** /

SELECT * FROM Employees
WHERE age=50 AND salary=5400;


/ ***** His joindate will come whose age is 30, and salary is 8000 ***** /

SELECT joinDate FROM Employees
WHERE age=30 AND salary=8000;


/ ***** The name whose age is 60, and salary is 9800 ***** /

SELECT name FROM Employees
WHERE age=60 AND salary=9800;


/ ***** The name and joinDate where age is 90, and salary is 3600 ***** /

SELECT name, joinDate FROM Employees
WHERE age=90 AND salary=3600;


/ ***** The salary and joinDate where name is nop, and age is 60 ***** /

SELECT salary, joinDate FROM Employees
WHERE name='nop' AND age=60;

SQL Where OR

The “where OR statement” is used where your 2 conditions are. But if one of your conditions is wrong and one is right then this statement will still work.

/ ***** The record whose age is 20, and salary is 5400 ***** /

SELECT name FROM Employees
WHERE age=20 OR salary=5400;


/ ***** The salary & joinDate will come where name is hij, and age is 40 ***** /

SELECT salary, joinDate FROM Employees
WHERE name=hij OR age=40;

SQL Where Like

The SQL like statement is used to extract some kind of data from the database. The LIKE operator searches the string and extracts the data when it matches. Learn how to use where like in SQL.

/ ***** Name which starts with a ***** /

SELECT * FROM Employees
WHERE name LIKE 'a%';


/ ***** Name which ends with g ***** /

SELECT * FROM Employees
WHERE name LIKE '%g';


/ ***** The name kl comes in between ***** /

SELECT * FROM Employees
WHERE name LIKE '%kl%';


/ ***** Name which starts with hi ***** /

SELECT * FROM Employees
WHERE name LIKE 'hi%';


/ ***** Only names that start with n, o and p character ***** /

SELECT * FROM Employees
WHERE name LIKE '[nop]%';


/ ***** Names between f to k ***** /

SELECT * FROM Employees
WHERE name LIKE '[f-k]%';


/ ***** The name that starts with e and ends with g ***** /

SELECT * FROM Employees
WHERE name LIKE 'e%g';


/ ***** The salary that starts at 2 ***** /

SELECT * FROM Employees
WHERE salary LIKE '2%';


/ ***** Only salary that start with 2, 5 and 3 ***** /

SELECT * FROM Employees
WHERE salary LIKE '[253]%';

SQL Where IN

The SQL Where IN statement is used to extract one or more records. Let’s know how to use SQL where IN statement.

/ ***** Those records will come whose salary is 2000, 5600, and 8000 ***** /

SELECT * FROM Employees
WHERE salary IN ('2000', '5600', '8000');


/ ***** Those records will come whose age is 20, 60, and 80 ***** /

SELECT name FROM Employees
WHERE age IN ('20', '60', '80');

SQL Keywords

We have some keywords of SQL available, which are used most commonly. Let’s know what those keywords are and what they mean.

NoKeywordsDescription
1CREATEIt is used to create a database and table
2CREATE DATABASEIt is used to create a database only
3CREATE TABLEIt is used to create a table
4DELETEIt is used to delete record from the table
5DROPIt is used to delete a column, database, and table
6DROP COLUMNIt is used to delete a column in the table
7DROP TABLEIt is used to delete a table
8FOREIGN KEYIt is used to join two tables together
9JOINIt is used to join the tables
10UPDATEIt is used to update the record in the table

SQL Frequently Asked Questions

We have answers to some questions that people search on the Internet every day. Let’s know what those questions are and what their answers are.

What does SQL mean?
SQL stands for Structured Query Language

How to extract data from the database?
Using the “SELECT” statement.

How to update data in the database?
Using the “UPDATE” statement.

How to delete data in the database?
Using the DELETE statement.

How to insert new data in the database?
Using the INSERT INTO statement.

how do you select a column named
Using the “SELECT MyName FROM Mytable” statement.

how do get the full table data?
Using the “SELECT * FROM Mytable” statement.

how do get different or distinct values?
Using the “SELECT DISTINCT ” statement.

how to sort the result?
Using ORDER BY keyword.

how to select a value within a range?
Using the BETWEEN keyword.

how to search for a specific pattern?
Using the LIKE keyword.

how to create a table in the database?
Using the CREATE TABLE keyword.

What does TRIM() Function?
It Removes spaces from a string.

What does the CONCAT() Function?
It Adds two strings together.

What does the LEN() Function?
It returns the length of the string.

What does the REPLICATE() Function?
It repeats the same string.

Related: 16 most useful examples of SQL between and not between