
July 6th, 2012, 07:10 PM
|
 |
A Change of Season
|
|
|
|
|
2 queris return same results, whichone is prefered?
I was reading an article in mysql.com and I saw this, I was wondering what the difference would be (in performance and in general better practice) between query A (that he used) and query B that I prefer:
Query A:
Code:
SELECT name,
population,
headofstate,
top.nr
FROM country,
(
/* 2 */
SELECT countrycode,
Count(*) AS nr
FROM countrylanguage
WHERE isofficial = 'T'
GROUP BY countrycode
HAVING nr = (
/* 3 */
SELECT Max(summary.nr_official_languages)
FROM (
/* 4 */
SELECT countrycode,
Count(*) AS nr_official_languages
FROM countrylanguage
WHERE isofficial = 'T'
GROUP BY countrycode) AS summary)) AS TOP
WHERE country.code = top.countrycode
Query B:
Code:
SELECT name,
population,
headofstate,
top.nr
FROM country
INNER JOIN (SELECT countrycode,
Count(*) AS nr
FROM countrylanguage
WHERE isofficial = 'T'
GROUP BY countrycode
HAVING nr = (SELECT Max(summary.nr_official_languages)
FROM (SELECT countrycode,
Count(*) AS nr_official_languages
FROM countrylanguage
WHERE isofficial = 'T'
GROUP BY countrycode) AS summary)) AS
TOP
ON country.code = top.countrycode
__________________
Devshed people, please fix the spell check:
System is temporarily busy. Please try again in a few seconds.
|