SQL where

In this tutorial, we explain how to use them where clause in SQL.

sql where clause

The SQL where clause is used to filter the results and fetch the particular data or record and the where clause conditions apply also in a SELECT, INSERT, UPDATE OR DELETE statement.

Syntax:

  
Where [conditions];

SELECT column1, column 2,column n ,...
FROM table_name WHERE condition; 
  
  

The SQL where clause is difficult to explain with syntax, so let's start the examples. Here we are creating a database and creating a table in SQL.


Just I create a table and named it a student table.


  
create table student(id int not null primary key,student_name varchar(25) not null,
class int not null,age int not null,phone_no varchar(20) not null);
  
  


some data should be inserted using the INSERT statement.



  
INSERT into student(id,student_name,class,age,phone_no) values(101,'varun', 6 , 15, 9874563211);
INSERT into student(id,student_name,class,age,phone_no) values(101,'varun', 6 , 16, 9874563211);
INSERT into student(id,student_name,class,age,phone_no) values(102,'arun', 6 , 15,8912345641);
INSERT into student(id,student_name,class,age,phone_no) values(103,'vishva', 6 , 15, 8974563211);
.
.
.
.
like the way insert the records.
  
  



This is the above insert record student table.

Enter the following SQL statement:


  
  select * from student where age=17;
  
  

SQL where


There will be 2 student records in age 17 the condition required is equal to the age 17 the record will be fetched from the database table.
  
  select * from student where age=15;
  
  

SQL where


In this example, there will be 5 records fetched from the database table.

Here, the where clause following operators can be used in the table to fetch the data.





Operators Description Links
= equal Click Here
> greater than Click Here
< less than Click Here
>= greater than or equal to Click Here
<= less than or equal to Click Here
BETWEEN certain range in the table Click Here
LIKE using the search pattern Click Here
IN specify the multiple possible values Click Here
Previous Post Next Post