Jump to content

Multiple SQL Statements

Guest pacmann

Recommended Posts

Guest pacmann

Hello Experts! I'm wondering if someone is willing to help me out. I went through the SQL tutorial at w3schools.com, but was still not able to resolve my problem. I'm trying to work through "multiple-level" SQL statements. I would like to see an example where I can combine SQL statements. If anyone can refer me to a good tutorial that teaches how to "combine" multiple-level SQL statements, or if you can give me an example of how I can combine them, I would greatly appreciate it. For clarification, I have summarized and scaled down what I am trying to do:

Tables & Fields (Simplified): [Athlete: AthID (Primary), FName, LName]Scores: 14Scores (14 fields, treated here as one field to simplify illustration), AthID (Foreign from Athlete table), DivID (Foreign from Division table)Division: DivID (Primary), DivName, MeetID (Foreign from Meet table)Meet: MeetID (Primary), MeetDate, MeetName
In other words, each Meet will have multiple Divisions, and each Division will have multiple Athletes/Scores[square brackets indicate no problems with this, pretty striaghtforward]
[sELECT Athlete.LName, Athlete.FName FROM Athlete WHERE Athlete.AthID = Request.Querystring("ID")]SELECT Scores.14Scores, Scores.DivID FROM Scores WHERE Scores.AthID = Request.Querystring("ID")SELECT Division.DivName, Division.MeetID FROM Division, Scores WHERE Division.DivID = Scores.DivIDSELECT Meet.MeetDate, Meet.MeetName FROM Meet, Division WHERE Meet.MeetID = Division.MeetID ORDER BY Meet.MeetDate DESC

Yielding (most recent Meet first):

[<h1>Athlete.FName Athlete.LName</h1>]<tr><td>Meet.MeetDate - Meet.MeetName</td><td>Division.DivName</td><td>Scores.14Scores</td></tr><tr><td>Meet.MeetDate - Meet.MeetName</td><td>Division.DivName</td><td>Scores.14Scores</td></tr>etc.

How do I combine all three SQL statements into one so I can sort the data by Meet Date, yet call the data by Athlete ID? Any insight you can give will be very much appreciated.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...