MySQL Check existence of a set of fields in a table -
i validating existence of set of field values (eg: yyy,aaa , ccc) in table , using union gather results, prefer more elegant , efficient solution:
tablename: example_table
name | class
xxx | cse <br> yyy | ee <br> zzz | mech <br> aaa | cse <br> bb | cse <br>
my query:
select if(name null,"yyy ","") example_table (name '%yyy%') union (select if(name null,"aaa ","") example_table (name '%aaa%')) union (select if(name null,"ccc ","") example_table (name '%ccc%'));
i need know of string values need not present in table. problem is, table using has around thousands of tuples , using union seems costly..
looking strings never elegant ;) if want shorten code, give in
try. similar to...
...where name in ('yyy','aaa','ccc')....
Comments
Post a Comment