Processing a mySQL subquery returning multiple rows

Here is my example:

select row_x from table_1 where row_y = (select row_a from table_2 where row_b = x) 

The problem I am facing is that my query should return multiple rows if the subquery returns multiple rows.

Ideally, this would mean something similar to:

  'select row_x from table_1 where row_y = '<first row from subquery>' or row_y = '<second row from subquery>' etc. 

How can i do this? Thanks!

+6
source share
2 answers

You are looking for an offer IN

 select row_x from table_1 where row_y IN ( select row_a from table_2 where row_b = x ) 
+15
source
 SELECT t1.row_x FROM table_1 t1 JOIN table_2 t2 ON t1.row_y=t2.row_a WHERE t2.row_b = x 
+2
source

Source: https://habr.com/ru/post/886819/


All Articles