Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Another MySql prob, getting max of count...

Options
  • 28-11-2005 7:28pm
    #1
    Registered Users Posts: 1,821 ✭✭✭


    Problem:

    2 tables Staff and Branch
    Share Bno as Identifier
    Branch has address(more than one column)
    Staff has a column called Sex, which determines whether male or female (obviously)

    So problem is I need the Max number of female employees employed by a certain branch and the address of that branch. Problem is I tried using count(*) which gives it something like this

    SELECT Bno,COUNT(*)
    FROM staff
    WHERE Sex = 'F'
    GROUP BY Bno

    But i can't get the data out for the highest number of female employees employed by the a certain branch.

    I also need to take from the branch table (address) and dont know how to do this without adding on the total of branch and staff, instead of just staff. Can anyone help me or at least point me in the right direction? Cheers


Comments

  • Registered Users Posts: 2,781 ✭✭✭amen


    post both tables and some sample data with what you expect vs what you get


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    This is cheating slightly, but it should work.
    SELECT staff.Bno, branch.address, COUNT(staff.*) as num_females
    FROM staff, branch
    WHERE staff.Sex = 'F' 
    AND staff.Bno = branch.Bno
    GROUP BY staff.Bno
    ORDER BY num_females DESC
    LIMIT 0, 1
    


  • Registered Users Posts: 1,821 ✭✭✭Skud


    that code works perfect, cheers man, helped alot.


Advertisement