MySQL query not working

Discussion in 'Web Development & Web Hosting' started by tech291083, Sep 3, 2006.

  1. tech291083

    tech291083 Bit Poster

    47
    0
    14
    i have just started learning php and mysql on my own after installig fedora 5 on my laptop just a week ago. i have creatd a table (winners) in mysql (from command line) and it has 2 columns. one is countryName and another is year. just like country and the year it won the football world cup. i want to make a query in terms of the names of the country/countries who have won the cup more than say 2 times. but i m struggling with it can any one help. the query i have created is

    select countryName,count(*) as numberOfWins from winners where count(*)>2 group by country order by numberOfWins asc;

    thanks.
     
  2. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    Perhaps not the most elegant method, and I'm away from my handy references, but try this:
    Code:
    select * from (select countryName, count(*) as numberOfWins from winners group by countryName) as a where numberOfWins >= 2;
    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  3. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    Cough - I forgot about 'having'.... Try this:

    select countryName, count(*) as numberOfWins from winners group by countryName having count(*) > 2;

    :oops:

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  4. tech291083

    tech291083 Bit Poster

    47
    0
    14
    thanks thanks a lot mate. it works
     

Share This Page

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.