How to solve 'subquery returns more than 1 row' in sql?


SELECT * FROM users WHERE id = (SELECT user_id FROM orders);

The subquery is returning multiple rows, making the comparison invalid.


Use the IN keyword for multiple results, or ensure the subquery only returns a single value.

SELECT * FROM users WHERE id IN (SELECT user_id FROM orders);

Beginner's Guide to SQL