MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 6th, 2012, 07:10 PM
zxcvbnm's Avatar
zxcvbnm zxcvbnm is offline
A Change of Season
Click here for more information.
 
Join Date: Mar 2004
Posts: 1,604 zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Weeks 5 Days 2 h 24 m 41 sec
Reputation Power: 71
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > 2 queris return same results, whichone is prefered?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap