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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Table join problem

Status
Not open for further replies.

brownfox

Programmer
Jan 5, 2003
173
GB
I've got two tables. Table1 is like this:
newPlayers.gif

Table2 is like this:
players_round1.gif

The values for white and black in table2 are the unique ID (primary key) from table1. It's a chess pairing program I'm trying to design. The thing is I need to check that there aren't any players in table2 who are from the same school.
This is all in visual basic (jet sql) and I'm guessing I need an inner join to compare the schools in table1 with the White and Black values in table2. Can anyone help?
Thanks in advance...
 
Join Table 2 to Table 1 twice - once for White and once for Black. Access will call the table 'Table1_1' or something similar automatically. Then do a where Table1.school <> table1_1.school. You'll find this easier if you normalise ie take the schools out of Table 1 and put them into Table 3.

Oooh - and call the tables by meaningful names.

 
Thanks for your suggestions Mike. It turns out that to normalise the tables (put the schools col in the table called players_round1) was harder than the SQL query I need which is...wait for it:
Code:
SELECT newPlayers.*
FROM (players_round1 INNER JOIN newPlayers ON players_round1.White = newPlayers.ID) INNER JOIN (players_round1 AS players_round1_1 INNER JOIN newPlayers AS newPlayers_1 ON players_round1_1.Black = newPlayers_1.ID) ON (newPlayers.County = newPlayers_1.County) AND (newPlayers.School = newPlayers_1.School);
But thanks again for your suggestions!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top