Monday, March 19, 2012

Another SQL Query!

Dear All,
I have two tables in my database, part of a tennis league results and
fixtures website I am putting together.
Results
id fixture_id home_team_rubbers away_team_rubbers
1 229 2 2
2 253 2 2
3 265 1 3
4 230 2 2
Fixtures Table
id home_team_id away_team_id match_date
229 20 26 2006-05-03
230 20 29 2006-05-31
231 20 45 2006-05-17
232 20 78 2006-06-28
233 20 79 2006-07-26
234 20 89 2006-07-12
235 26 20 2006-06-20
236 26 29 2006-07-25
237 26 45 2006-07-11
238 26 78 2006-05-16
239 26 79 2006-06-13
240 26 89 2006-05-30
253 78 20 2006-05-09
265 89 20 2006-05-23
What I want to do it list all the fixture (based on fixure id) that
don't have a result associated with the fixture through an SQL query.
The resulting output from the query that I desire is the following.
Query Output
fixture_id
231
232
233
234
235
236
237
238
239
240
Any ideas how I can do this?
Cheers,
SimonTry:
select
f.id
from
Fixtures f
where not exists
(
select
*
from
Results r
where
r.fixture_id = f.id
)
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
.
<simon.stockton@.baesystems.com> wrote in message
news:1149375877.441866.70510@.i40g2000cwc.googlegroups.com...
Dear All,
I have two tables in my database, part of a tennis league results and
fixtures website I am putting together.
Results
id fixture_id home_team_rubbers away_team_rubbers
1 229 2 2
2 253 2 2
3 265 1 3
4 230 2 2
Fixtures Table
id home_team_id away_team_id match_date
229 20 26 2006-05-03
230 20 29 2006-05-31
231 20 45 2006-05-17
232 20 78 2006-06-28
233 20 79 2006-07-26
234 20 89 2006-07-12
235 26 20 2006-06-20
236 26 29 2006-07-25
237 26 45 2006-07-11
238 26 78 2006-05-16
239 26 79 2006-06-13
240 26 89 2006-05-30
253 78 20 2006-05-09
265 89 20 2006-05-23
What I want to do it list all the fixture (based on fixure id) that
don't have a result associated with the fixture through an SQL query.
The resulting output from the query that I desire is the following.
Query Output
fixture_id
231
232
233
234
235
236
237
238
239
240
Any ideas how I can do this?
Cheers,
Simon|||Select f.id
From Fixtures f
Left Join Results r on f.id = r.fixture_id
Where r.id Is Null
Order By f.id
Tom
<simon.stockton@.baesystems.com> wrote in message
news:1149375877.441866.70510@.i40g2000cwc.googlegroups.com...
> Dear All,
> I have two tables in my database, part of a tennis league results and
> fixtures website I am putting together.
> Results
> id fixture_id home_team_rubbers away_team_rubbers
> 1 229 2 2
> 2 253 2 2
> 3 265 1 3
> 4 230 2 2
> Fixtures Table
> id home_team_id away_team_id match_date
> 229 20 26 2006-05-03
> 230 20 29 2006-05-31
> 231 20 45 2006-05-17
> 232 20 78 2006-06-28
> 233 20 79 2006-07-26
> 234 20 89 2006-07-12
> 235 26 20 2006-06-20
> 236 26 29 2006-07-25
> 237 26 45 2006-07-11
> 238 26 78 2006-05-16
> 239 26 79 2006-06-13
> 240 26 89 2006-05-30
> 253 78 20 2006-05-09
> 265 89 20 2006-05-23
> What I want to do it list all the fixture (based on fixure id) that
> don't have a result associated with the fixture through an SQL query.
> The resulting output from the query that I desire is the following.
> Query Output
> fixture_id
> 231
> 232
> 233
> 234
> 235
> 236
> 237
> 238
> 239
> 240
> Any ideas how I can do this?
> Cheers,
> Simon
>|||Thanks guys, much appreciated!

No comments:

Post a Comment