Skip to content
Advertisement

Mysql subquery in where clause that returns comma separated value

I’m not really good at subqueries, here’s the sample tables that I have.

I’m trying to get the order names using this query, but I’m only getting one result. I’m not sure if this is possible.

Advertisement

Answer

Your primary effort should go into fixing your design. You should not be storing several integer values in a string column. If each order belongs to a single customer, then the customer id should be stored in the orders table. If an order may belong to multiple customers at once, then you need a bridge table, with one row per customer/order tuple.

That said: for you current design, you can use find_in_set():

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement