0

I have a string returned from a function "'aa','bb','cc',..."(the function uses GROUP_CONCAT). I want to use this as a condition in the IN clase of mysql.

SELECT name,class,comment
FROM vwstudent v
WHERE name IN (select func())

I want the query to act like

SELECT name,class,comment
FROM vwstudent v
WHERE name IN ('aa','bb','cc','dd',..)

I assume ('aa','bb','cc','dd',..) is acting as a whole string here and isn't generating any result. What can I do to run this query error less.

Noam Rathaus
  • 5,405
  • 2
  • 28
  • 37
Kamal
  • 77
  • 1
  • 2
  • 8
  • 1
    The string is generated by `GROUP_CONCAT()`? Then you should probably be joining the tables and forgetting about `GROUP_CONCAT()` and `IN()`. Classic [XY Problem](http://meta.stackexchange.com/q/66377). – eggyal Dec 08 '13 at 09:10
  • See this answer: http://stackoverflow.com/a/19465469/575376 – juergen d Dec 08 '13 at 09:11
  • Or see this one: http://stackoverflow.com/a/11425315/149076 – Jim Dennis Dec 08 '13 at 09:14

1 Answers1

0

I'm not sure if it'll help. But you might be able to hack something together by using PREPARE and EXECUTE as described here: How To have Dynamic SQL in MySQL Stored Procedure

... but that's completely new to me. I've never used anything like that in MySQL.

Community
  • 1
  • 1
Jim Dennis
  • 17,054
  • 13
  • 68
  • 116