473,774 Members | 2,191 Online
Bytes | Software Development & Data Engineering Community
+ 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.Even tNameID
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.EventI D = MeetEvents.Even tNameID INNER JOIN Students on Results.Student 1 = 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 6257
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.Student X > 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
4663
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 sequential joins. eg. if i have 4 tables A, B, C, D and the join conditions are A Inner join B, B Inner Join C, C Left Outer join D then i am constructing joins as :
8
4975
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 also display their corresponding entries in arb, but if there is NO entry in arb I still want it to show up as NULL or something, so that I can get the attention that there IS no language associated with that article.
7
31564
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" slows the system down considerably. I've tried creating a temp db, but I can't figure out how to execute two select commands. (It throws the exception "The column prefix 'tempdb' does not match with a table name or alias name used in the query.")
4
8095
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 CHIP ----------- ---------- 1 Lays 1 Ruffles 1 Ruffles
16
5726
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 got a nudge in the right direction from Mr. Kreft. I promised to provide details once working, so here it is. The code is shown below. My next step is to build this technique into my application. I'm hoping for substantial performance gain. ...
52
6351
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 variations(combination of fields), - then act on each group in some way ...eg ProcessRs (oRs as RecordSet)... the following query will get me the distinct groups
2
19722
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 some of these joins are inner joins and some are Left outer joins. table1 inner joined with table 2 table2 inner join with table3 table2 inner join with table4 table2 left join with table5
2
3169
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 delimited values when joining multiple tables. I have one table called 'floorplans' which has two fields (floorplan_jpg & floorplan_pdf), I'd like each of these fields to return arrays of the same length (they have the same # of values in the data...
1
10052
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 where t3.Id is null This query is having 2 left joins.
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10046
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6717
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5358
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.