How to solve "subquery returns more than 1 row" error
P粉235202573
2023-08-21 17:36:57
<p>I have a query that returns multiple rows, and another query where I want to set the condition to be a value for any one of these multiple rows, so basically I want the subquery to look like this: </p>
<pre class="brush:php;toolbar:false;">select *
from table
where id= (multi-row query);</pre>
<p>Where <code>Multi-row query</code> returns multiple rows. So if the values of these rows are 1, 2, 3, then I want the id to be set to 1 or 2 or 3. </p>
You can use
in()
:Or use connection:
Connections are never a worse choice in terms of performance, and depending on the circumstances and the database you are using, may provide better performance.
=
can be used when a subquery returns only one value.When a subquery returns multiple values, you need to use
IN
:For example: