MySQL Forums
Forum List  »  General

Subquery returning NULL, why?
Posted by: Alan Lee
Date: January 13, 2016 06:34AM

I don't understand why the following query will return NULL in column v.

DROP TABLE IF EXISTS tbl_test;
CREATE TABLE tbl_test ( a INT, b INT );
INSERT INTO tbl_test VALUES (1,1),(2,2),(3,3);

SELECT t2.a,
( SELECT t3.a
FROM tbl_test t3
LEFT JOIN tbl_test t4 ON t4.b = 999
WHERE t3.a = t2.a ) AS v
FROM tbl_test t1
JOIN tbl_test t2 ON t2.a = t1.a
WHERE t1.b = 3
GROUP BY t2.a

If I change 999 to 1, the correct value (i.e. 3) is retrieved.
BTW, MySQL version is 5.1.57.

Options: ReplyQuote


Subject
Written By
Posted
Subquery returning NULL, why?
January 13, 2016 06:34AM
January 13, 2016 07:09AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.