The SQL WHERE clause is used to specify a condition while fetching the data from table extract only those records that fulfill a specified condition.
The basic syntax of the SELECT statement with the WHERE clause is as shown below.
SELECT * FROM table_name WHERE [condition]
Consider the tbl_student_record table having the following records
id | name | class | subject | city | phone | fee | fee_date |
---|---|---|---|---|---|---|---|
1 | Mohan | 2nd | Math | Agra | 999999990 | 500 | 2018-01-02 |
2 | Pooja | 3rd | English | Delhi | 999999991 | 200 | 2018-01-11 |
3 | Rahul | 4th | Math | Agra | 999999992 | 300 | 2018-01-05 |
4 | Suresh | 2nd | English | Agra | 999999993 | 400 | 2018-01-22 |
5 | Vivek | 3rd | Math | Agra | 999999994 | 500 | 2018-01-01 |
6 | Anuj | 2nd | English | Delhi | 999999995 | 600 | 2018-01-31 |
7 | Sanju | 4th | Math | Agra | 999999996 | 400 | 2018-01-17 |
8 | Rohit | 3rd | English | Delhi | 999999997 | 700 | 2018-01-10 |
9 | Mahesh | 3rd | Math | Agra | 999999998 | 800 | 2018-01-24 |
10 | Munesh | 4th | English | Delhi | 999999999 | 200 | 2018-01-09 |
Condtion 1 : We want to get tbl_student_record who belongs to agra city.
SELECT * FROM tbl_student_record WHERE city='Agra'
Note : In where clause, String always comes under single quote or double quote Ex - 'Agra'
Output
1 | Mohan | 2nd | Math | Agra | 999999990 | 500 | 2018-01-02 |
3 | Rahul | 4th | Math | Agra | 999999992 | 300 | 2018-01-05 |
4 | Suresh | 2nd | English | Agra | 999999993 | 400 | 2018-01-22 |
5 | Vivek | 3rd | Math | Agra | 999999994 | 500 | 2018-01-01 |
7 | Sanju | 4th | Math | Agra | 999999996 | 400 | 2018-01-17 |
9 | Mahesh | 3rd | Math | Agra | 999999998 | 800 | 2018-01-24 |
Condtion 2 : We want that record where the fee is greater than 500rs.
SELECT * FROM tbl_student_record WHERE fee>500
Output
6 | Anuj | 2nd | English | Delhi | 999999995 | 600 | 2018-01-31 |
8 | Rohit | 3rd | English | Delhi | 999999997 | 700 | 2018-01-10 |
9 | Mahesh | 3rd | Math | Agra | 999999998 | 800 | 2018-01-24 |
To Learn More in Hindi watch this Video
How to use where clause in mysql Query
If love this tutorial Please Like this page