Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Joining the same table twice to another table 1

Status
Not open for further replies.

BasicBoy

Programmer
Feb 22, 2008
156
ZA
I have this query which I cannot get to work :

MyQuery$ = "Select

transactions.id,
transactions.transdate,
transactions.description,

votes.votename as firstvotename,
votes.votename as secondvotename

from

(((Transactions

LEFT JOIN Votes ON Transactions.paidby=Votes.voteno)
LEFT JOIN Votes ON Transactions.paidfor=Votes.voteno)

I would appreciate help, thanks
 
you need to use aliases
Code:
SELECT transactions.id
     , transactions.transdate
     , transactions.description
     , [blue]pb_votes[/blue].votename AS paidby_votename
     , [blue]pf_votes[/blue].votename AS paidfor_votename 
  FROM (
       transactions 
INNER
  JOIN votes [blue]AS pb_votes[/blue]
    ON [blue]pb_votes[/blue].voteno = transactions.paidby
       )
INNER
  JOIN votes [blue]AS pf_votes[/blue]
    ON [blue]pf_votes[/blue].voteno = transactions.paidfor
note i made them INNER JOINs because it's unlikely that you would allow a transcation to be made for vote names which don't exist

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top