Reply
three tables with 2 joins
Old 02-04-2008, 11:08 AM three tables with 2 joins
ChipJohns's Avatar
I don't know! Do you?

Posts: 477
Name: Chip Johns
Location: Savannah Georgia
Hi guys, I am trying to learn more about joins, so this is just a few tables I threw together to learn with. That's why the table names andcolumn names are so simple...

I am trying to pull info from three tables.. I am first trying to get the sql statement to work before moving on to displaying data. This is giving me the following message...

Syntax error (missing operator) in query expression 'a.b_id = b.b_id JOIN c ON b.c_id = c.c_id'.

Here is my code:

Code:
 
<%
strQ = "SELECT a_name, a_id, a.b_id, a.c_id, b.c_id, b.b_name, c.c_name FROM a"
strQ = strQ & " INNER JOIN b"
strQ = strQ & " ON a.b_id = b.b_id"
strQ = strQ & " JOIN c"
strQ = strQ & " ON b.c_id = c.c_id;"
 
objRS.Open strQ
%>
any help is much appreciated...

Thanks,

Chip
ChipJohns is offline
Reply With Quote
View Public Profile Visit ChipJohns's homepage!
 
When You Register, These Ads Go Away!
     
Old 02-04-2008, 04:20 PM Re: three tables with 2 joins
Novice Talker

Posts: 5
it has to be LEFT JOIN, not just JOIN to work...
atlantictech is offline
Reply With Quote
View Public Profile
 
Old 02-05-2008, 12:02 AM Re: three tables with 2 joins
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,945
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
The other thing I find works is to put your first join in brackets:
Code:
strQ = "SELECT a_name, a_id, a.b_id, a.c_id, b.c_id, b.b_name, c.c_name FROM (a"
strQ = strQ & " INNER JOIN b"
strQ = strQ & " ON a.b_id = b.b_id)"
strQ = strQ & " INNER JOIN c"
strQ = strQ & " ON b.c_id = c.c_id;"
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 02-05-2008, 12:16 PM Re: three tables with 2 joins
ChipJohns's Avatar
I don't know! Do you?

Posts: 477
Name: Chip Johns
Location: Savannah Georgia
Adam, I tried it and it works!. I am excited...! I am making an honest effort to truly understand as much about asp as I can...

I can do easy stuff but am truly excited about learning some more.

Thanks very much.

I'm also going to try the LEFT JOIN too. I do want to learn as much as I can.

Thanks a lot.

Chip
ChipJohns is offline
Reply With Quote
View Public Profile Visit ChipJohns's homepage!
 
Old 02-06-2008, 04:29 AM Re: three tables with 2 joins
chrishirst's Avatar
Super Moderator

Posts: 11,865
Location: Blackpool. UK
http://www.w3schools.com/sql/sql_join.asp

JOIN syntax
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-07-2008, 09:08 AM Re: three tables with 2 joins
ChipJohns's Avatar
I don't know! Do you?

Posts: 477
Name: Chip Johns
Location: Savannah Georgia
Thanks Chris,

This is great! I'll put w3schools on my favorites...
ChipJohns is offline
Reply With Quote
View Public Profile Visit ChipJohns's homepage!
 
Old 02-07-2008, 10:51 AM Re: three tables with 2 joins
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,945
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Good thinking, Chip. W3Schools about the only time you'll ever see the W3 explain things in English as opposed to doublespeak.

Glad the query worked for you, too!
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Reply     « Reply to three tables with 2 joins
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.15046 seconds with 13 queries