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 that I am running into is that my query needs to return multiple rows if the subquery returns multiple rows.
Ideally it would translate to 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 make this happen? Thanks!
Multiple Row Sub Query Multiple-row subqueries are nested queries that can return more than one row of results to the parent query. Multiple-row subqueries are used most commonly in WHERE and HAVING clauses. Since it returns multiple rows, it must be handled by set comparison operators (IN, ALL, ANY).
When the subquery returns one or more rows of values, the subquery is only evaluated once and then the row(s) of values is returned to outer query to use.
Answer: B. Multiple-row subqueries return more than one row of results. Operators that can be used with multiple-row subqueries include IN, ALL, ANY, and EXISTS.
You are looking for IN clause
select row_x from table_1
where row_y
IN (
select row_a from table_2 where row_b = x
)
SELECT t1.row_x FROM table_1 t1 JOIN table_2 t2 ON t1.row_y=t2.row_a WHERE t2.row_b = x
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With