Can I use IN with strings?

Hi everyone,

please help me with a query. Do you think the following should work, or is it only possible with integers? I am trying to return those columns where one row has a field named beer, and one row has a field named wine. Do to the current setup, I’m unable to use the row ID. Or is this impossible?

The echoed-out query looks like this:

WHERE name = ‘simon’ && booz IN (beer,wine)

Thank you in advance!!

rows cannot possibly have differently named columns

but yes, you can use IN with strings, and even with column names

pro tip: use AND instead of &&

Hi Rudy,

thank you. For some reason I get the error:

mysql_num_rows() expects parameter 1 to be resource, boolean given.

Must the strings be quoted perhaps?

i don’t do php but you get this because your query died before it executed and you’re not testing for successful execution (don’t ask me how to do that) before using mysql_num_rows()

if they’re strings and not column names, yeah

:slight_smile:

Okay thank you, perhaps that is the reason for the error.

Hope you have a good weekend.

Cheers