If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > three table not exists problem (was "I need help!")

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-21-05, 03:29
mrbear mrbear is offline
Registered User
 
Join Date: Mar 2004
Posts: 21
three table not exists problem (was "I need help!")

i got 3 tables. user , teams , upload

user contain userid & email
teams contain teamid & leaderid & gen(contain null)
upload contain teamid

leaderid = userid

The gen column must be = "gener"

I need to know the email colums of those team who is not in the upload table. HELP!!

Last edited by mrbear; 02-21-05 at 03:33.
Reply With Quote
  #2 (permalink)  
Old 02-21-05, 06:59
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
Would this work?
Code:
SELECT u.userid, u.email
  FROM USER u
 WHERE u.userid IN (
                   SELECT t.leaderid
                     FROM teams t
                    WHERE t.gen = 'gener'
                          AND t.teamid NOT IN (SELECT l.teamid
                                                 FROM upload l));
Reply With Quote
  #3 (permalink)  
Old 02-21-05, 10:56
jay82 jay82 is offline
Registered User
 
Join Date: Feb 2005
Location: London
Posts: 19
Faster Version

SELECT USER.*
FROM USER
LEFT OUTER JOIN TEAM ON USER.UserId = TEAM.LeaderID
LEFT OUTER JOIN UPLOAD ON TEAM.TeamId = UPLOAD.TeamId
WHERE UPLOAD.TeamId = Null

This will show you all the users who is not in upload team
even if user is no assigned to any team

If you want to show only users which are assigned to some team and not in upload table use following query

SELECT USER.*
FROM USER
LEFT OUTER JOIN TEAM ON USER.UserId = TEAM.LeaderID
LEFT OUTER JOIN UPLOAD ON TEAM .TeamId = UPLOAD.TeamId
WHERE UPLOAD.TeamId = Null
AND TEAM.LeaderID <> Null


Hope this will work...!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On