If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > need a query to join 3 tables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-01-05, 06:33
asif_8 asif_8 is offline
Registered User
 
Join Date: Jan 2005
Posts: 5
Red face need a query to join 3 tables

hi everyone - wondering if anyone can help me in this: i have got 3 tables i.e
1.Invoice
2.Customer
3.Agents
and i want to generate an invoice using the info from these two tables how can i do that. the scenario is that for one invoice there can be multiple entries

invID,CustID,AgentID,productPrice |
1 1 1 £40 |
1 2 2 £50 | this is the data for 1 invoice
1 3 3 £70 |
i want a join query so that i can get the names of the customers and agents on behalf of their ids in the invoice table and all the info from invoice table so that it can show the result like this

invID,CustName,AgentName,productPrice |
1 xyz a £40 |
1 yyy b £50 | this is the data for 1 invoice
1 zzz c £70 |

================================================== =======
Reply With Quote
  #2 (permalink)  
Old 02-01-05, 06:48
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Code:
select invID
     , CustName
     , AgentName
     , productPrice
  from Invoice
inner
  join Customer
    on Invoice.CustID
     = Customer.CustID
inner
  join Agents
    on Invoice.AgentID
     = Agents.AgentID
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-01-05, 07:18
asif_8 asif_8 is offline
Registered User
 
Join Date: Jan 2005
Posts: 5
thank you thats what i wanted
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On