sql - Different approach of using IN clause in MySql -


today have posted answer query this

select * table_name column_name in (val1,val2,...) 

some user has posted answer query this

select * table_name val1 in (column_name) 

as can see here position of column_name , values interchanged.

from mysql docs

expr in (value,...)

returns 1 if expr equal of values in in list, else returns 0. if values constants, evaluated according type of expr , sorted. search item done using binary search. means in quick if in value list consists entirely of constants.

mysql> select 2 in (0,3,5,7); -> 0  mysql> select 'wefwf' in ('wee','wefwf','weg'); -> 1 

as says above one(my query) correct. both above queries produce same output.

also why not other approach in listed in mysql documentation?

this question serves canonical information source regarding use of in. purpose have detailed, high quality answers detailing proper use on in in queries.

you raised question connected answer here.

in simple explanation using statements below,

select * tablename column1 in (1, 2, 3, 4) -- versus select * tablename 1 in (column1, column2, column3, column4) 

the first statement involves one column being compared multiple values.

select  *   tablename  column1 = 1 or        column1 = 2 or        column1 = 3 or        column1 = 4 

while second statement a value compared multiple columns.

select  *   tablename  column1 = 1 or        column2 = 1 or        column3 = 1 or        column4 = 1 

which bit different 1 another.


update 1

here's third form of in clause:


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -