MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 18th, 2007, 01:57 PM
AdamG AdamG is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2007
Posts: 1 AdamG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 36 sec
Reputation Power: 0
Need help with joins

I am having a nightmare with this query

SELECT Employee.ssn
FROM Employee
INNER JOIN Manages on Employee.ssn = Manages.ssn
WHERE
(SELECT COUNT(e.ssn) as SSN, d.dno
FROM Employee e
INNER JOIN Manages m ON e.ssn = m.ssn
INNER JOIN Works w ON m.dno = w.dno
INNER JOIN Department d ON w.dno = d.dno
GROUP BY e.ssn, d.dno
HAVING COUNT(e.ssn) > 5
);

The bold bit is the original query where it finds all departments where these is more than 5 employees. I need to find the ssn of the employee who manages that department.

In MySQL it points to the nested select whereas in Oracle it says Too many values

Here is the table structure

I have been struggling to create this query all dat and am ready to give up

I want to select all employee_ids who manages a department with more than 5 employees

Employee table
-------------------
ssn (primary key)

Manages table
------------------
ssn(foreign key)
dno(foreign key)

Works_in table
------------------
ssn (foreign key)
dno(foreign key)

Department table
----------------------
dno(primary key)

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Need help with joins


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway