Sql where clause

Sql where clause

Blog Bustle 14/03/2020

Sql where clause is used to filter sql query result. When we apply any condition using where clause in sql query then sql query return those results which fulfill that condition. We can use sql where clause with select, delete and update sql query. Sql where clause can also be used with sql joins.

Sql where clause syntax

1. Sql where clause with select query

select column_1, column_2, column_3, ....
from table_name where condition;

2. Sql where clause with update query

update table_name
set column_1 = value_1,
column_2 = value_2,
column_3 = value_3,
....
where condition;

3. Sql where clause with delete query

delete column_1, column_2, column_3, ....
from table_name where condition;

Sql where clause example

For example, i have student table.

id name city state
1 gaurav lucknow uttar pradesh
2 robin agra uttar pradesh
3 neha amritsar punjab
4 gurmeet patiala punjab

i want to fetch those records from student table where city is lucknow then sql select query will be

select * from student where city = 'lucknow';

id name city state
1 gaurav lucknow uttar pradesh

now i am going to change city name where id is 1 and sql update query will be

update student set city = 'agra' where id = 1;

id name city state
1 gaurav agra uttar pradesh
2 robin agra uttar pradesh
3 neha amritsar punjab
4 gurmeet patiala punjab

now i am going to delete all record from student table where name is 'robin' and sql delete query will be

delete from student where name = 'robin';

id name city state
1 gaurav agra uttar pradesh
3 neha amritsar punjab
4 gurmeet patiala punjab

Remember that first select database then run any sql query related to that database otherwise you will get 'no database selected' error.

So we can easily use sql where clause with select, delete and update sql query. Hope you like this tutorial.

Other important links

Insert query in mysql

Update query in mysql

Delete query in mysql

Select query in mysql

Sql distinct keyword

Sql where clause searches:

Tags: #mysql