0

I am using a sub query to get all qcodes and passing it as a parameter to another query in mysql. But inner query is returning value like -

SELECT qcodes FROM boardmst WHERE id=10

10002','10028','10031','10202','10226

so how to parse it to pass in another query with IN clause?

SELECT * FROM users WHERE qcodes IN (SELECT qcodes FROM boardmst WHERE id=10)
O. Jones
  • 103,626
  • 17
  • 118
  • 172
Yugal Kishor Bais
  • 199
  • 1
  • 1
  • 8

2 Answers2

0

Apart from the missing quotes on the outside (maybe it's not the exact answer the inner question produces) this is exactly what MySQL expects as the content of an IN clause. You just have to be sure that the definition of the qcodes column is identical between the users and the boardmst tables.

0

If you have only five values as comma separated then below query can come in handy :

SELECT * FROM users WHERE qcodes IN (
select regexp_substr(replace(qcodes,''',''',','),'[^, ]+',1,level)
from boardmst where id = 10 connect by level <= 5)
Nikhil Shetkar
  • 346
  • 1
  • 9