‘In’ clause in mysql

By | January 10, 2014

‘In’ clause wirll replace many ‘OR’s

Example for fetching data using ‘In’.

——————————————————
|id|Name |Age|
——————————————————
|1|vasanthan|32|
|2|John |44|
|3|Michael |34|
|4|Rani |39|
|5|Raina |38|
|6|Rajendra |25|
|7|Sharon |18|
——————————————————-

Select * from mydoubts_table_users where age IN(34,32,38);
——————————————————
|id|Name |Age|
——————————————————
|1|vasanthan|32|
|3|Michael |34|
|5|Raina |38|
——————————————————-

Suppose if we use the query using ‘or’ clause it will be like as below

Select * from mydoubts_table_users where age =34 or age=32 or age=38;