Following two queries are exactly same, except the country name. In Query 1 its 'Malaysia' & in Query 2 its 'India'.
The query itself is erroneous; Since I am using "ac.country
" in first subquery whereas i actually needed to use "ass.country
", but still i am getting result in Query 1 whereas I get NULL in Query 2.
Can someone explain why this is happening.
Query 1:
SELECT DATE(DAY) AS daycust,
(SELECT SUM(Quantity) AS webss
FROM ACQ AS ass
WHERE ass.day = ac.day
AND ac.country IN (SELECT DISTINCT aam.country_name FROM accounts AS aam)
AND country = 'Malaysia') AS webss
FROM analytics_country AS ac
WHERE DAY BETWEEN '2016-07-01' AND '2016-08-02'
AND ac.country IN (SELECT DISTINCT aam.country_name FROM accounts AS aam)
AND country = 'Malaysia'
GROUP BY daycust
ORDER BY daycust
Query 2:
SELECT DATE(DAY) AS daycust,
(SELECT SUM(Quantity) AS webss
FROM ACQ AS ass
WHERE ass.day = ac.day
AND ac.country IN (SELECT DISTINCT aam.country_name FROM accounts AS aam)
AND country = 'India') AS webss
FROM analytics_country AS ac
WHERE DAY BETWEEN '2016-07-01' AND '2016-08-02'
AND ac.country IN (SELECT DISTINCT aam.country_name FROM accounts AS aam)
AND country = 'India'
GROUP BY daycust
ORDER BY daycust
Note : I would also like to add that the output varies across different versions of MySql.
In Server version: "5.5.30-tokudb-7.0.1-MariaDB-log" -> Both the queries work fine.
In Server version: "5.5.41-tokudb-7.5.5-MariaDB - MariaDB Server" -> Only Query 1 works fine.