I got "error: #1242 - Subquery returns more than 1 row" trying to execute this Query:
SELECT id FROM postcodes WHERE pcd LIKE (SELECT CONCAT(pcd,' %') FROM towns WHERE id IN (31898,12828,15771,7604))
do you have any suggestion for this query?
JOIN the two tables instead of the IN predicate, like this:
SELECT p.id
FROM postcodes p
INNER JOIN towns t ON p.pcd LIKE CONCAT(t.pcd,' %')
WHERE t.id IN (31898,12828,15771,7604);
Check this query :
SELECT CONCAT(pcd,' %') FROM towns WHERE id IN (31898,12828,15771,7604)
Maybe it's result is more than one row.
Or you can limit the subquery result.
SELECT id FROM postcodes WHERE pcd LIKE (SELECT CONCAT(pcd,' %') FROM towns WHERE id IN (31898,12828,15771,7604) LIMIT 1)
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