Selasa, 26 November 2013

RE: [MS_AccessPros] Help with query

 

Phil-

 

OK.  Try this:

 

SELECT Matches.*, Derbies.*

FROM Matches, Derbies

WHERE ((Matches.hometeamID = Derbies.Team1) OR (Matches.hometeamID = Derbies.Team2))

AND ((Matches.awayteamID = Derbies.Team1) OR (Matches.awayTeamID = Derbies.Team2))

 

That should show you all the Matches that have a Derbies record where the two teams show up.  Sadly, the query won't be updatable, but you will be able to see the ratings data you want to update your matches.

 

John Viescas, Author

Microsoft Access 2010 Inside Out

Microsoft Access 2007 Inside Out

Microsoft Access 2003 Inside Out

Building Microsoft Access Applications

SQL Queries for Mere Mortals

http://www.viescas.com/

(Paris, France)

 

 

 

From: MS_Access_Professionals@yahoogroups.com [mailto:MS_Access_Professionals@yahoogroups.com] On Behalf Of Phil Knowles
Sent: Tuesday, November 26, 2013 6:24 PM
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] Help with query

 




Hi John

 

No, the field derby in the matches table is to be updated with the appropriate rating from the derbies table (ie either rating1 or rating2 depending on whether team1 or team2 from the derbies record is the home team of the matches record).

 

Phil

 

On Tuesday, 26 November 2013, 14:24, John Viescas <JohnV@msn.com> wrote:

 

Phil-

 

You note a field called "derby" in the Matches table.  Is this the same as the ID in the Derbies table?  Or, are you looking for any previous Derby that has these two teams as either Home or Away?

 

If you can answer my questions, I may be able to suggest a solution.

 

John Viescas, Author

Microsoft Access 2010 Inside Out

Microsoft Access 2007 Inside Out

Microsoft Access 2003 Inside Out

Building Microsoft Access Applications

SQL Queries for Mere Mortals

(Paris, France)

 

 

 

From: MS_Access_Professionals@yahoogroups.com [mailto:MS_Access_Professionals@yahoogroups.com] On Behalf Of pdk444444@yahoo.co.uk
Sent: Tuesday, November 26, 2013 2:34 PM
To: MS_Access_Professionals@yahoogroups.com
Subject: [MS_AccessPros] Help with query

 



Hi

 

I am having trouble working out how best to create this query and I wondered if someone could give me some pointers.

 

I have the following tables (relevant data only)

 

Teams

id

team name

 

Matches

id

date

hometeamid   (looks up team name from teams.id)

awayteam id   (looks up team name from teams.id)

derby

 

Derbies

id

team1    (looks up team name from teams.id)

team2    (looks up team name from teams.id)

rating1    (this is a rating for this derby fixture when team1 is the home team)

rating2    (this is a rating for this derby fixture when team2 is the home team)

 

when a match record has been created (by bulk external import) I want to be able to update the record if applicable with the correct derby rating.

 

A match has a home team and an away team and I want to find (if it exists) the derby record for this match and then pick up the appropriate rating figure depending on which team is at home.

 

So from the match record I need to establish if there is a derby record for the 2 teams involved and then apply a rating depending on whether hometeam id = team1 or team2

 

I suspect I will need at least one level of 'prequery' but as I say I can't get my head around it at the moment

 

Help please!!

 

Phil



 




__._,_.___
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (10)
Recent Activity:
.

__,_._,___

Tidak ada komentar:

Posting Komentar