mysql  where  clause

the MySQL where clause is used to filter records.

the where clause in MySQL is used to fetch only those records that fulfill a specified criterion.

the where clause allows you to specify exact rows to select based on given conditions.

mysql where syntax

                   select    column_name,  column_name, ....
 
                   from       table_name
                      
                   where     column_name    operator   value ;

note :- the  where clause is used not only with the select statement but also other sql statements to filter rows such as delete and update .

below is a selection from the "user" table:

useridfirstnamelastnamemobilenocity
1sandeepkumar9549293245india
2ramkumar9549293212usa
3shyamdhaka2323234545jaipur
4ankitnehra3423567845uae
5radhakumari2323121212jaipur

MySQL where clause example

the following mysql statement selects all the user from the userid 4, in the "user" table :

 
              mysql> select      *          from        user 
      
               where       userid = 4 ;

note :- numeric values do not have to be inside quotes.

output :-

useridfirstnamelastnamemobilenocity
4ankitnehra3423567845uae

note :- and & or can be used to combine conditions :

 
               select      *          from        user 
      
               where       userid = 1   and   firstname = 'sandeep' ; 
               

output :-

useridfirstnamelastnamemobilenocity
1sandeepkumar9549293245india

the following operator can be used in the where clause :

operatordescription
=equal
<>not equal
<less than
>greater than
<=less than or equal
>=greater than or equal
betweenbetween an inclusive range
likesearch for a pattern
inspecify multiple possible values for a column