Woodie Posted August 31, 2003 Share Posted August 31, 2003 Hope soembody can help me! I have two tables. One has the names of teams and a primary key identifying the team. The other table has list of fixtures using the team IDs and time stamps of the fixtures. TableTeams teamID TeamName TableFixtures fixID HomeTeamID awayTeamID timStam I want a query that will list all the teamnames given in TeamName that DO NOT appear in the Fixtures table when timStam is between two specified values! Please Help I have tried several times with the only succes not getting an error! Link to comment https://forums.phpfreaks.com/topic/966-left-join-query-help-needed/ Share on other sites More sharing options...
Dissonance Posted August 31, 2003 Share Posted August 31, 2003 [php:1:3b4f32b051] $sql = \"SELECT TeamName FROM TableTeams WHERE TeamName.teamID != TableFixtures.HomeTeamID AND TeamName.teamID != awayTeamID AND TableFixtures.timStam > [value1] AND TableFixtures.timStam < [value2]\" [/php:1:3b4f32b051] Value 1 and Value 2 will be your two limiting values, obviously. In all honesty, though, I think you\'re better off using two separate queries. This type of join isn\'t very efficient, imo. Link to comment https://forums.phpfreaks.com/topic/966-left-join-query-help-needed/#findComment-3259 Share on other sites More sharing options...
Barand Posted August 31, 2003 Share Posted August 31, 2003 To do it without subquries you\'ll need to create a temporary table [php:1:0a0e51b533]<?php mysql_query( \" create table tmpfix (teamID int, fixID int)\"); mysql_query( \"INSERT INTO tmpfix SELECT HomeTeamID, fixID FROM tablefixtures WHERE timStam BETWEEN \'$a\' and \'$b\'\"); mysql_query( \"INSERT INTO tmpfix SELECT awayTeamID, fixID FROM tablefixtures WHERE timStam BETWEEN \'$a\' and \'$b\'\"); $res = mysql_query(\"select teamname from teams t left join tmpfix f on t.teamID = f.teamID where f.fixID is NULL\"); ?>[/php:1:0a0e51b533] hth Link to comment https://forums.phpfreaks.com/topic/966-left-join-query-help-needed/#findComment-3261 Share on other sites More sharing options...
Woodie Posted September 1, 2003 Author Share Posted September 1, 2003 Thanks for the tips I will try it out and see what happens! Link to comment https://forums.phpfreaks.com/topic/966-left-join-query-help-needed/#findComment-3283 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.