Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql script

Status
Not open for further replies.

Arjan80

Programmer
Oct 17, 2001
3
NL
I have to made a result of soccerteams who does NEVER played on field 1

There are 3 tables that can be used for this one (the connections)
table 1 named: team table 2 named: game table 3 named: home
t_code g_code g_code
teamname t_code fieldnr
class opponent
trainer date
leader arbiter

I have wrote this:
select distinct te.t_code, te.teamname
from team te join game g on te.t_code = g.t_code and
g_code not in (select h.g_code from thuis h where h.fieldnr = '1');

If I execute this sql I get 12 teams (it has to be 8), the reason I know:
if a team 1 time not played on field 1, so on field 2 for example it will be printed on the screen, but the possibility is that the same team has ever played on field 1.

Can anyone help? The use of Except and Minus is not allowed.
af227

thnx,
Arjan
 
This query has all of the teams that played on field 1. These are the ones you don't want.

Code:
SELECT DISTINCT t_code
  FROM game
  JOIN home ON game.g_code = home.g_code
WHERE home.fieldnr = 1


So, this query has the teams that never played on field 1.

Code:
SELECT t_code FROM team
WHERE t_code NOT IN (
   SELECT DISTINCT t_code
     FROM game
     JOIN home ON game.g_code = home.g_code
   WHERE home.fieldnr = 1
)

maybe.
 
Thanks!!! You are wonderfull!!!

It was quiet easy when I saw that script. Sometimes I got a headache of those sql scripts, lol...

Arjan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top