Jump to content

LEFT JOIN Query help needed


Woodie

Recommended Posts

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
Share on other sites

[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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.