473,493 Members | 3,174 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem with multiple joins

5 New Member
Howdy folks,

I am new to the site and new to joins, so I'm hoping I can get some much needed assistance.

Using ASP, VBscript & an Access 2003 db, I am building a page to display results from track and field events, and am struggling with joining information from 3 tables.

I will try to explain what I have and what I am doing as clearly as possible.

Table 1 - Results
MeetID - Field used to select records from Results table
sLevel - Include here only because it is mentioned in the code
EventID - Relation: MeetEvents.EventNameID
Student1 - Relation: Students.ID
Student2 - Relation: Students.ID
Student3 - Relation: Students.ID
Student4 - Relation: Students.ID

Table 2 - MeetEvents
EventNameID - Key
EventName
DisplayOrder
EventTypeID

Table 3 - Students
StudentID - Key
First
Last
Middle

Select Statement:
Expand|Select|Wrap|Line Numbers
  1. SELECT Results.*, MeetEvents.*, Students.First, Students.Last, Students.Middle FROM Results 
  2. INNER JOIN MeetEvents on Results.EventID = MeetEvents.EventNameID
  3. INNER JOIN Students on Results.Student1 = Students.ID 
  4. WHERE Results.MeetID = 80
  5. ORDER BY Results.sLevel, MeetEvents.EventTypeID, MeetEvents.DisplayOrder 
  6.  
Error Received:
Microsoft JET Database Engine (0x80040E14)
Syntax error (missing operator) in query expression 'Results.EventID = MeetEvents.EventNameID INNER JOIN Students on Results.Student1 = Students.ID'.

Additional information:
EventID will always exist.
Student1 Will always match a record in Students.ID.
Student2-4 Will be zero if it was a single student event, otherwise, each will match a StudentID (The code does not reflect this, because until I've figured out how to get the information for Student1, I haven't really considered how I will get the information for Student2-4).

I hope that this is enough (but not too much) information and that somebody can help.

Thank you.

SeaviewBlue
Apr 12 '07 #1
7 6244
MMcCarthy
14,534 Recognized Expert Moderator MVP
The primary key in students table is StudentID not ID

Expand|Select|Wrap|Line Numbers
  1. SELECT Results.*, MeetEvents.*, Students.First, Students.Last, Students.Middle 
  2. FROM ((Results INNER JOIN MeetEvents 
  3. ON Results.EventID = MeetEvents.EventNameID)
  4. INNER JOIN Students 
  5. ON Results.Student1 = Students.StudentID) 
  6. WHERE Results.MeetID = 80
  7. ORDER BY Results.sLevel, MeetEvents.EventTypeID, MeetEvents.DisplayOrder 
  8.  
Mary
Apr 13 '07 #2
SeaviewBlue
5 New Member
The primary key in students table is StudentID not ID

Expand|Select|Wrap|Line Numbers
  1. SELECT Results.*, MeetEvents.*, Students.First, Students.Last, Students.Middle 
  2. FROM ((Results INNER JOIN MeetEvents 
  3. ON Results.EventID = MeetEvents.EventNameID)
  4. INNER JOIN Students 
  5. ON Results.Student1 = Students.StudentID) 
  6. WHERE Results.MeetID = 80
  7. ORDER BY Results.sLevel, MeetEvents.EventTypeID, MeetEvents.DisplayOrder 
  8.  
Mary
Thank you Mary,

It appears that properly parenthesizing the join statements did the trick.

The StudentID vs ID was my mistake - ID is the actual key, but StudentID is another field in the table that is not being used.

I seem to be lost on how to parenthesize the join statements, but I'm going to experiment now to see if I can get the Student2-4 fields joined in.

Thanks Again!

SeaviewBlue
Apr 13 '07 #3
MMcCarthy
14,534 Recognized Expert Moderator MVP
Thank you Mary,

It appears that properly parenthesizing the join statements did the trick.

The StudentID vs ID was my mistake - ID is the actual key, but StudentID is another field in the table that is not being used.

I seem to be lost on how to parenthesize the join statements, but I'm going to experiment now to see if I can get the Student2-4 fields joined in.

Thanks Again!

SeaviewBlue
You're welcome
Apr 13 '07 #4
SeaviewBlue
5 New Member
Thank you Mary,

It appears that properly parenthesizing the join statements did the trick.

The StudentID vs ID was my mistake - ID is the actual key, but StudentID is another field in the table that is not being used.

I seem to be lost on how to parenthesize the join statements, but I'm going to experiment now to see if I can get the Student2-4 fields joined in.

Thanks Again!

SeaviewBlue
I am sorry to report that I have not been able to figure out how to join information from the Students table for Student2-4.

These 3 fields will only find a match on Students.ID when Results.StudentX > 0.

Once again, any assistance would be greatly appreciated.

Thank you,

SeaviewBlue
Apr 15 '07 #5
MMcCarthy
14,534 Recognized Expert Moderator MVP
Try this and see if it does what you want.

Expand|Select|Wrap|Line Numbers
  1. SELECT Results.*, MeetEvents.*, Students.First, Students.Last, Students.Middle 
  2. FROM (((((Results INNER JOIN MeetEvents 
  3. ON Results.EventID = MeetEvents.EventNameID)
  4. LEFT JOIN Students As S1 ON Results.Student1 = S1.StudentID) 
  5. LEFT JOIN Students As S2 ON Results.Student1 = S2.StudentID)
  6. LEFT JOIN Students As S3 ON Results.Student1 = S3.StudentID)
  7. LEFT JOIN Students As S4 ON Results.Student1 = S4.StudentID)
  8. WHERE Results.MeetID = 80
  9. ORDER BY Results.sLevel, MeetEvents.EventTypeID, MeetEvents.DisplayOrder
Apr 16 '07 #6
SeaviewBlue
5 New Member
Try this and see if it does what you want.

Expand|Select|Wrap|Line Numbers
  1. SELECT Results.*, MeetEvents.*, Students.First, Students.Last, Students.Middle 
  2. FROM (((((Results INNER JOIN MeetEvents 
  3. ON Results.EventID = MeetEvents.EventNameID)
  4. LEFT JOIN Students As S1 ON Results.Student1 = S1.StudentID) 
  5. LEFT JOIN Students As S2 ON Results.Student1 = S2.StudentID)
  6. LEFT JOIN Students As S3 ON Results.Student1 = S3.StudentID)
  7. LEFT JOIN Students As S4 ON Results.Student1 = S4.StudentID)
  8. WHERE Results.MeetID = 80
  9. ORDER BY Results.sLevel, MeetEvents.EventTypeID, MeetEvents.DisplayOrder
Mary - The join's were perfect!

With a little tweaking, here is the code I end up with, that actually gives me what I was looking for:
Expand|Select|Wrap|Line Numbers
  1. SELECT Results.*, MeetEvents.*, 
  2. S1.First & S1.Middle & S1.Last AS S1Name, 
  3. S2.First & S2.Middle & S2.Last AS S2Name, 
  4. S3.First & S3.Middle & S3.Last AS S3Name, 
  5. S4.First & S4.Middle & S4.Last AS S4Name 
  6. FROM (((((Results INNER JOIN MeetEvents ON Results.EventID = MeetEvents.EventNameID) 
  7. LEFT JOIN Students As S1 ON Results.Student1 = S1.ID) 
  8. LEFT JOIN Students As S2 ON Results.Student2 = S2.ID) 
  9. LEFT JOIN Students As S3 ON Results.Student3 = S3.ID) 
  10. LEFT JOIN Students As S4 ON Results.Student4 = S4.ID) 
  11. WHERE Results.MeetID = 80 
  12. ORDER BY Results.sLevel, MeetEvents.EventTypeID, MeetEvents.DisplayOrder
  13.  
Thank you once again - Your help has been greatly appreciated.

SeaviewBlue
Apr 16 '07 #7
MMcCarthy
14,534 Recognized Expert Moderator MVP
Mary - The join's were perfect!

With a little tweaking, here is the code I end up with, that actually gives me what I was looking for:
Expand|Select|Wrap|Line Numbers
  1. SELECT Results.*, MeetEvents.*, 
  2. S1.First & S1.Middle & S1.Last AS S1Name, 
  3. S2.First & S2.Middle & S2.Last AS S2Name, 
  4. S3.First & S3.Middle & S3.Last AS S3Name, 
  5. S4.First & S4.Middle & S4.Last AS S4Name 
  6. FROM (((((Results INNER JOIN MeetEvents ON Results.EventID = MeetEvents.EventNameID) 
  7. LEFT JOIN Students As S1 ON Results.Student1 = S1.ID) 
  8. LEFT JOIN Students As S2 ON Results.Student2 = S2.ID) 
  9. LEFT JOIN Students As S3 ON Results.Student3 = S3.ID) 
  10. LEFT JOIN Students As S4 ON Results.Student4 = S4.ID) 
  11. WHERE Results.MeetID = 80 
  12. ORDER BY Results.sLevel, MeetEvents.EventTypeID, MeetEvents.DisplayOrder
  13.  
Thank you once again - Your help has been greatly appreciated.

SeaviewBlue
You're welcome.
Apr 16 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4643
by: Prem | last post by:
Hi All Database Gurus, I am trying to write code which will produce all the possible valid queries, given tables and join information for tables. Right now i am just trying to construct all the...
8
4957
by: Matt | last post by:
Hello I have to tables ar and arb, ar holds articles and a swedish description, arb holds descriptions in other languages. I want to retreive all articles that match a criteria from ar and...
7
31534
by: Steve | last post by:
I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three "Left Outer Joins" in order to return every transaction for a specific set of criteria. Using three "Left Outer Joins"...
4
8078
by: Jim | last post by:
I'm having trouble doing multiple counts with groups, ordering, and joins. Can someone help me out? Below is two table samples and what I'm trying to get my output to be: TABLEA ID ...
16
5682
by: Randy Harris | last post by:
I was inspired by the recent discussion of returning multiple recordsets to ADO from a stored procedure. (Amazed is probably more accurate). I asked about how to accomplish same with Oracle and...
52
6268
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
2
19711
by: narendra vuradi | last post by:
Hi I have a requirement where in i haev to convert the SQL from Oracle to the one which will run on the SQL server. in the Oracle Query i am doing multiple joins, between some 13 tables. and...
2
3145
by: beargrease | last post by:
I'm kind of comfortable with basic joins, but a current project requires a complex query of many tables. The GROUP_CONCAT(DISTINCT ...) function has been very useful as returning my values as comma...
1
10027
by: silpa | last post by:
Hi, I have an SQL query like this select distinct t1.prodID from Table1 t1 left join Table2 t2 on t2.prodID = t1.prodID left join Table3 t3 on t3.serialno = t2.Id and t3.Qty = 0 ...
0
6989
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6873
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7367
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5453
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4889
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1400
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
644
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.