[MySQL+PHP] SELECT -> Ignore condition if zero rows?

Hi,

I have this example mysql_query:

mysql_query("SELECT * FROM table WHERE id='$id' AND name NOT IN($names)");

Is there any option in mysql_query to get results even if this returns Zero rows, i.e. run query ignoring that second condition?

I know it's easy to use PHP if() but I'm just curious whether is possible to do it inside one mysql_query.

Thanks for ideas!
Aidam-UnlimitedAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
you could do this:
mysql_query("SELECT * FROM table WHERE id='$id' AND ( name NOT IN($names) OR NOT EXISTS(  SELECT * FROM table WHERE id='$id' AND ( name NOT IN($names))  ))");

Open in new window

0
 
Lukasz ChmielewskiConnect With a Mentor Commented:
0
 
Aidam-UnlimitedAuthor Commented:
Thanks to both of you guys!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.