Get Started: SQL WHERE Clause

In This Article You Will Know About SQL WHERE Clause. 

SQL WHERE Clause – Before moving ahead, let’s know a bit about Top Python Skills.

Table of Contents

SQL WHERE Clause

The SQL Where clause is used to get the records from the section (column-row) where the specified condition is specified.

WHERE Syntax:

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

				
			

Note: The WHERE clause is not used only in the SELECT clause but also used in other SQL clauses such as UPDATE, DELETE, etc.

Example Database

Below is the example of a database table named “details”.

Id

Name

class

section_id

1

Alex

5

1

2

Rolex

6

2

3

Salex

7

2

4

Lelex

8

3

5

Kelex

9

5

WHERE – SELECT *

Example: Use WHERE clause to return the records after matching specified conditions.

				
					SELECT * FROM details
WHERE section_id = 2;
				
			

WHERE – SELECT FROM specified column

Example: Use WHERE clause to return the records after matching specified conditions.

				
					SELECT class
FROM details
WHERE name = 'Lelex';

				
			

WHERE Operator

WHERE – Greater than operator

Example: Use WHERE clause to return the records after matching specified conditions.

				
					SELECT * FROM details
WHERE section_id > 2;
				
			

WHERE – Less than operator

Example: Use WHERE clause to return the records after matching specified conditions.

				
					SELECT * FROM details
WHERE section_id < 5;
				
			

WHERE – Greater than or equal operator

Example: Use WHERE clause to return the records after matching specified conditions.

				
					SELECT * FROM details
WHERE section_id >= 3;

				
			

WHERE – Less than or equal operator

Example: Use WHERE clause to return the records after matching specified conditions.

				
					SELECT * FROM details
WHERE section_id <= 5;
				
			

WHERE – Not equal operator

Example: Use WHERE clause to return the records after matching specified conditions.

				
					SELECT * FROM details
WHERE section_id <> 3;
				
			

Note: In some SQL version, not equal operator is defined as != too.

WHERE – BETWEEN operator

Search for a certain range.

Example: Use WHERE clause to return the records after matching specified conditions.

				
					SELECT * FROM details
WHERE section_id BETWEEN 2 AND 5;
				
			

Note: You will learn later about SQL AND clause.

WHERE – LIKE operator

Search for a pattern.

Example: Use WHERE clause to return the records after matching specified conditions.

				
					SELECT * FROM details
WHERE name LIKE '%x';

				
			

Note: You will learn later about SQL AND clause.

WHERE – IN operator

Search between multiple conditions.

Example: Use WHERE clause to return the records after matching specified conditions.

				
					SELECT * FROM details
WHERE section_id IN (2, 5);
				
			

If you find anything incorrect in the above-discussed topic and have further questions, please comment below.

Connect on:

Recent Post

Popular Post

Top Articles

Archives
Categories

Share on