0

I have to just select the values from outer query based on the result set of inner query.

Table 1:
row 1 : abc   
row 2: def

Table 2: row 1: column name doc_id values = 1,2 (comma separated values)

select * from table 1 where id IN (select doc_id from table 2)

but it shows me only one row, it has to show two rows.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
GI Joes
  • 27
  • 4
  • 1
    Please fix your formatting. And you should avoid using CSV in your table. – Tim Biegeleisen Jan 10 '16 at 06:40
  • Possible duplicate of [INNER JOIN ON vs WHERE clause](http://stackoverflow.com/questions/1018822/inner-join-on-vs-where-clause) – Vidya Sagar Jan 10 '16 at 06:40
  • table 2 has one record with csv like 1,2,3 , how to pass it in subquery if I pass it in subquery the subquery return this as a staring not searching for each – GI Joes Jan 10 '16 at 06:49
  • do you mean table2 has 1 row with two (or possibly more) comma separated values you need to explode into 2 (or possibly more) rows? – Zahiro Mor Jan 10 '16 at 07:06

1 Answers1

2

Sounds like find_in_set is what you're looking for:

SELECT *
FROM   table1 
WHERE  EXISTS (SELECT *
               FROM   table2
               WHERE  FIND_IN_SET (table1.id, table2.doc_id) > 0)
Mureinik
  • 297,002
  • 52
  • 306
  • 350