• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

sql SELECT problem

 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a java program which connects to a MySQL server and performs simple tasks like adding, removing and updating entries. I am also creating some reports but i am stuck on 1 select query which isnt giving me the desired output.
The tables needed for this query are:
Staff: StaffID, Staff_Name

Modules: ModuleID, Module_Name, Credits

Teaches: StaffID, ModuleID

I am trying to select the staff members who teach more than one module, so far i have this

SELECT Staff.Staff_Name FROM Staff INNER JOIN (SELECT StaffID FROM Teaches GROUP BY StaffID HAVING COUNT(DISTINCT ModuleID) > 1)Teaches ON Teaches.StaffID = Teaches.StaffID

But this is giving me output of

Staff 1
Staff 1
Staff 2
Staff 2
Staff 3
Staff 3

Where staff 1 teaches two modules, staff 2 teaches three modules and Staff 3 only teaches one module
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Really???

 
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try GROUPing and HAVING clauses ;)

WP
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic