SQL Where Clause - The Coding Shala

Home >> Learn SQL >> SQL Where Clause

SQL Where Clause

In SQL 'Where' clause is used to filter out our result based on some certain condition. SQL 'Where' clause is a data manipulation language statement. It can be used in 'select', 'update', 'delete' etc. For example, if you want to fetch certain rows whose id is mentioned.
SQL Where Clause - The Coding Shala

SQL Where Clause Syntax -

The basic SQL syntax with Where Clause is as follows - 

 SELECT column1, column2, columnN   
 FROM table_name  
 WHERE [condition]  

  • In the 'Where' Clause we can use the following operators to filter out our result -

Operator     Description  
 =            Equal  
 <> or !=     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          To specify multiple possible values for a column  

SQL Where Clause Example - 

The following SQL query without Where Clause  - 



 sql >> select * from Persons  
  
output >>  
 PersonID     LastName     FirstName     Address     City  
 1             Saini     Akshay           A-101     Pune  
 1             last         first           A-101     Pune  
 2             null         Akshay         null     null  

The following SQL query with SQL Where Clause - 

 sql >> select * from Persons  
          where  
         PersonId = 2  
  
output >>  
 PersonID     LastName     FirstName     Address     City  
 2             null         Akshay         null     null  
  • Here we used the '=' operator to compare like this we can use 'where' clause with other operators and in other statements to filter out our result.


Other Posts You May Like
Prev<< SQL UPDATE Query                                                                             NEXT >>SQL Having Clause
Please leave a comment below if you like this post or found some error, it will help me to improve my content.

Comments

Popular Posts from this Blog

LeetCode - Crawler Log Folder Solution - The Coding Shala

N-th Tribonacci Number Solution - The Coding Shala

Java Program to Convert Binary to Decimal - The Coding Shala

New Year Chaos Solution - The Coding Shala

Java Program to Find LCM of Two Numbers - The Coding Shala