I`m trying to run a nested query on MySQL (phpmyadmin) and via PHP, and both result in the same output which is incorrect.
NOTE: Table name have been clipped due to sensitivity of project
SELECT * FROM `table1` WHERE ID="SELECT `field1` FROM `table2` WHERE ID=1"
This returns zero rows, although each query alone gives a valid output as below
SELECT `field1` FROM `table2` WHERE ID=1
Gives the required output, and this output when used in the first part of the main query provides also what is required. Please help.
Don’t enclose it in quotes. Instead enclose it in parentheses:
If multiple rows are expected from the subquery, use
WHERE ID IN (SELECT...)instead ofWHERE ID=(SELECT...)You’ll probably get better performance with a
JOINthough: