mysql conditional query - complicated!

Posted by emre on Stack Overflow See other posts from Stack Overflow or by emre
Published on 2010-05-31T07:26:45Z Indexed on 2010/05/31 7:32 UTC
Read the original article Hit count: 235

Filed under:
|
|

i want to get distinct values for a field, let say: field1... ok this needs a query like: "select distint(field1) from table"

however for some records, field1 is empty and there is another column that is an alternative to field1, which is field2. now; for the records where field1 is empty i need to use the value of field2. i think i need sort of a conditional select statement with if control something like:

"select distinct( (if(field1!='') field1 else field2) ) from table"

but i have no idea on how to write it. any help is appricated...

© Stack Overflow or respective owner

Related posts about mysql

Related posts about conditional