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: -
SELECT Results.*, MeetEvents.*, Students.First, Students.Last, Students.Middle FROM Results
-
INNER JOIN MeetEvents on Results.EventID = MeetEvents.EventNameID
-
INNER JOIN Students on Results.Student1 = Students.ID
-
WHERE Results.MeetID = 80
-
ORDER BY Results.sLevel, MeetEvents.EventTypeID, MeetEvents.DisplayOrder
-
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
7 6257 MMcCarthy 14,534
Recognized Expert Moderator MVP
The primary key in students table is StudentID not ID -
SELECT Results.*, MeetEvents.*, Students.First, Students.Last, Students.Middle
-
FROM ((Results INNER JOIN MeetEvents
-
ON Results.EventID = MeetEvents.EventNameID)
-
INNER JOIN Students
-
ON Results.Student1 = Students.StudentID)
-
WHERE Results.MeetID = 80
-
ORDER BY Results.sLevel, MeetEvents.EventTypeID, MeetEvents.DisplayOrder
-
Mary
The primary key in students table is StudentID not ID -
SELECT Results.*, MeetEvents.*, Students.First, Students.Last, Students.Middle
-
FROM ((Results INNER JOIN MeetEvents
-
ON Results.EventID = MeetEvents.EventNameID)
-
INNER JOIN Students
-
ON Results.Student1 = Students.StudentID)
-
WHERE Results.MeetID = 80
-
ORDER BY Results.sLevel, MeetEvents.EventTypeID, MeetEvents.DisplayOrder
-
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
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
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
MMcCarthy 14,534
Recognized Expert Moderator MVP
Try this and see if it does what you want. -
SELECT Results.*, MeetEvents.*, Students.First, Students.Last, Students.Middle
-
FROM (((((Results INNER JOIN MeetEvents
-
ON Results.EventID = MeetEvents.EventNameID)
-
LEFT JOIN Students As S1 ON Results.Student1 = S1.StudentID)
-
LEFT JOIN Students As S2 ON Results.Student1 = S2.StudentID)
-
LEFT JOIN Students As S3 ON Results.Student1 = S3.StudentID)
-
LEFT JOIN Students As S4 ON Results.Student1 = S4.StudentID)
-
WHERE Results.MeetID = 80
-
ORDER BY Results.sLevel, MeetEvents.EventTypeID, MeetEvents.DisplayOrder
Try this and see if it does what you want. -
SELECT Results.*, MeetEvents.*, Students.First, Students.Last, Students.Middle
-
FROM (((((Results INNER JOIN MeetEvents
-
ON Results.EventID = MeetEvents.EventNameID)
-
LEFT JOIN Students As S1 ON Results.Student1 = S1.StudentID)
-
LEFT JOIN Students As S2 ON Results.Student1 = S2.StudentID)
-
LEFT JOIN Students As S3 ON Results.Student1 = S3.StudentID)
-
LEFT JOIN Students As S4 ON Results.Student1 = S4.StudentID)
-
WHERE Results.MeetID = 80
-
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: -
SELECT Results.*, MeetEvents.*,
-
S1.First & S1.Middle & S1.Last AS S1Name,
-
S2.First & S2.Middle & S2.Last AS S2Name,
-
S3.First & S3.Middle & S3.Last AS S3Name,
-
S4.First & S4.Middle & S4.Last AS S4Name
-
FROM (((((Results INNER JOIN MeetEvents ON Results.EventID = MeetEvents.EventNameID)
-
LEFT JOIN Students As S1 ON Results.Student1 = S1.ID)
-
LEFT JOIN Students As S2 ON Results.Student2 = S2.ID)
-
LEFT JOIN Students As S3 ON Results.Student3 = S3.ID)
-
LEFT JOIN Students As S4 ON Results.Student4 = S4.ID)
-
WHERE Results.MeetID = 80
-
ORDER BY Results.sLevel, MeetEvents.EventTypeID, MeetEvents.DisplayOrder
-
Thank you once again - Your help has been greatly appreciated.
SeaviewBlue
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: -
SELECT Results.*, MeetEvents.*,
-
S1.First & S1.Middle & S1.Last AS S1Name,
-
S2.First & S2.Middle & S2.Last AS S2Name,
-
S3.First & S3.Middle & S3.Last AS S3Name,
-
S4.First & S4.Middle & S4.Last AS S4Name
-
FROM (((((Results INNER JOIN MeetEvents ON Results.EventID = MeetEvents.EventNameID)
-
LEFT JOIN Students As S1 ON Results.Student1 = S1.ID)
-
LEFT JOIN Students As S2 ON Results.Student2 = S2.ID)
-
LEFT JOIN Students As S3 ON Results.Student3 = S3.ID)
-
LEFT JOIN Students As S4 ON Results.Student4 = S4.ID)
-
WHERE Results.MeetID = 80
-
ORDER BY Results.sLevel, MeetEvents.EventTypeID, MeetEvents.DisplayOrder
-
Thank you once again - Your help has been greatly appreciated.
SeaviewBlue
You're welcome.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 :
|
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.
|
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.")
|
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
|
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.
...
| |
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
|
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
|
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...
|
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.
|
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,...
|
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...
| |
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...
|
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,...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |