Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Old 05-16-2006, 10:18 AM two left joins
Experienced Talker

Posts: 48
Trades: 0
hi guys,

ive got an aspx page connecting to an MS ACCESS database.

im trying to do two left joins!


here is my code for one left join which works:

Dim sqlCmd2 = "SELECT ur.student_id, ur.unit_id, ur.award, aw.title " _
& "FROM UNITREG ur LEFT JOIN AWARD aw ON ur.award = aw.id " _
& "WHERE ur.student_id = '"& id &"' " _
& "ORDER BY aw.title"

i want to add a join to another table which i think should be something like this:

Dim sqlCmd2 = "SELECT ur.student_id, ur.unit_id, ur.award, aw.title, un.title " _
& "FROM UNITREG ur LEFT JOIN AWARD aw ON ur.award = aw.id, UNIT un " _
& "UNITREG ur2 LEFT JOIN UNIT un ON ur2.unit_id = un.id " _
& "WHERE (ur.student_id = '"& id &"')" _
& "ORDER BY aw.title"

i pritty sure im on the right lines but get thie following error:

Syntax error (missing operator) in query expression 'ur.award = aw.id UNITREG ur2 LEFT JOIN UNIT un ON ur2.unit_id = un.id'.

i prosume this means the i am not seperating my two join statements correctly.

i have tried "," and AND with no luck!

any ideas???????
__________________
regards,

Pauly.
The true sign of intelligence is not knowledge but imagination. (Albert Einstein)
Be who you are and say what you feel,
because those who mind don't matter and those who matter don't mind. (Dr. Seuss
)
paulwebmaster is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-16-2006, 10:28 AM Re: two left joins
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
wrap your first JOIN in parantheses

Code:
Dim sqlCmd2 = "SELECT ur.student_id, ur.unit_id, ur.award, aw.title, un.title " _ 
& "FROM (UNITREG ur LEFT JOIN AWARD aw ON ur.award = aw.id, UNIT un " _ 
& "UNITREG ur2 ) LEFT JOIN UNIT un ON ur2.unit_id = un.id " _
& "WHERE (ur.student_id = '"& id &"')" _ 
& "ORDER BY aw.title"
look to be in the right places
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-16-2006, 10:29 AM Re: two left joins
Experienced Talker

Posts: 48
Trades: 0
some other code i tryed:

Dim sqlCmd2 = "SELECT ur.student_id, ur.unit_id, ur.award, aw.title, un.title "
_ & "FROM UNITREG ur LEFT JOIN AWARD aw ON ur.award = aw.id "
_ & "LEFT JOIN UNIT un ON ur.unit_id = un.id "
_ & "WHERE (ur.student_id = '"& id &"')"
_ & "ORDER BY aw.title"
__________________
regards,

Pauly.
The true sign of intelligence is not knowledge but imagination. (Albert Einstein)
Be who you are and say what you feel,
because those who mind don't matter and those who matter don't mind. (Dr. Seuss
)
paulwebmaster is offline
Reply With Quote
View Public Profile
 
Old 05-16-2006, 10:33 AM Re: two left joins
Experienced Talker

Posts: 48
Trades: 0
chris,

i tryed this

Dim sqlCmd2 = "SELECT ur.student_id, ur.unit_id, ur.award, aw.title, un.title "
_ & "FROM (UNITREG ur LEFT JOIN AWARD aw ON ur.award = aw.id, UNIT un "
_ & "UNITREG ur2 ) LEFT JOIN UNIT un ON ur2.unit_id = un.id "
_ & "WHERE (ur.student_id = '"& id &"')"
_ & "ORDER BY aw.title"


and got following error:

Syntax error in JOIN operation.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Syntax error in JOIN operation.
__________________
regards,

Pauly.
The true sign of intelligence is not knowledge but imagination. (Albert Einstein)
Be who you are and say what you feel,
because those who mind don't matter and those who matter don't mind. (Dr. Seuss
)
paulwebmaster is offline
Reply With Quote
View Public Profile
 
Old 05-16-2006, 10:39 AM Re: two left joins
Experienced Talker

Posts: 48
Trades: 0
thanks Chris,

i managed to get it sorted!!!!
i used the brackets and tidied up my code!

thanks for that!!!!!!!

Dim sqlCmd2 = "SELECT ur.student_id, ur.unit_id, ur.award, aw.title, un.title "
_ & "FROM (UNITREG ur LEFT JOIN AWARD aw ON ur.award = aw.id) "
_ & "LEFT JOIN UNIT un ON ur.unit_id = un.id "
_ & "WHERE (ur.student_id = '"& id &"')"
_ & "ORDER BY aw.title"

u r the man!!!!!
__________________
regards,

Pauly.
The true sign of intelligence is not knowledge but imagination. (Albert Einstein)
Be who you are and say what you feel,
because those who mind don't matter and those who matter don't mind. (Dr. Seuss
)
paulwebmaster is offline
Reply With Quote
View Public Profile
 
Old 05-16-2006, 10:46 AM Re: two left joins
Experienced Talker

Posts: 48
Trades: 0
ok now i am trying three joins

Dim sqlCmd2 = "SELECT ur.student_id, ur.unit_id, ur.award, aw.title, un.title, re.title "
_ & "FROM (UNITREG ur LEFT JOIN AWARD aw ON ur.award = aw.id) "
_ & "(LEFT JOIN UNIT un ON ur.unit_id = un.id) "
_ & "LEFT JOIN RESULT re ON ur.grade = re.id "
_ & "WHERE (ur.student_id = '"& id &"')"
_ & "ORDER BY aw.title"


with following error:

Syntax error in FROM clause.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Syntax error in FROM clause.

any ideas??????
__________________
regards,

Pauly.
The true sign of intelligence is not knowledge but imagination. (Albert Einstein)
Be who you are and say what you feel,
because those who mind don't matter and those who matter don't mind. (Dr. Seuss
)
paulwebmaster is offline
Reply With Quote
View Public Profile
 
Old 05-16-2006, 10:58 AM Re: two left joins
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
now it starts to get complicated with nested parantheses

move the parantheses at the beginning of the second join to before the first parantheses

Code:
_ & "FROM ((UNITREG ur LEFT JOIN AWARD aw ON ur.award = aw.id) " 
_ & "LEFT JOIN UNIT un ON ur.unit_id = un.id) " 
_ & "LEFT JOIN RESULT re ON ur.grade = re.id " 
_ & "WHERE (ur.student_id = '"& id &"')"
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-16-2006, 11:24 AM Re: two left joins
Experienced Talker

Posts: 48
Trades: 0
Excellent!

thanks a lot
__________________
regards,

Pauly.
The true sign of intelligence is not knowledge but imagination. (Albert Einstein)
Be who you are and say what you feel,
because those who mind don't matter and those who matter don't mind. (Dr. Seuss
)
paulwebmaster is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to two left joins
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.83672 seconds with 12 queries