Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
jsweazy
Starting Member
3 Posts |
Posted - 2008-10-15 : 01:58:59
|
Ok so i have to do this:Write a query that would tell you the name of the customer that placed order 21610, and the name of the REP who represents this customer.Ok to explain the question the CustomerName is in the Customer table, the Order_Num is in the Order table and the Rep_Name is in the Rep Table. In the Order table there is a CustomerNum that has the customers number, which will get the CustomerName in the Customer table. Also in the Customer table there is a Rep_Num field that will help get the RepName in the Rep tableSo pretty much what i need to do is look up the Order_Num in the Orders table and get the corresponding CustomerNum. I need to use the CustomerNum to Select the corresponding CustomerName in the Customer table. And i also need to use the CustomerNum to get its Corresponding Rep_Num from the Customer table. Once i get the Rep_Num i need to use it to get the RepName in the Rep table. I need the query to just output the CustomerName and RepNameSee i understand what i need to do but i dont know how to do it.I have no clue to how to query all these at once and just outputing what i needIf you guys could help me write a query or point me to the functions i need to write it |
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-10-15 : 03:54:40
|
you need to join these table together. start by reading up on INNER JOIN. have a go at it and come back if you need some help with it. once you understand the joins, it will be simple queryEm |
|
|
jsweazy
Starting Member
3 Posts |
Posted - 2008-10-15 : 17:10:46
|
quote: Originally posted by elancaster you need to join these table together. start by reading up on INNER JOIN. have a go at it and come back if you need some help with it. once you understand the joins, it will be simple queryEm
Thanks I Figured it outHere is what i did:SELECT Customer.CustomerName, Rep.FirstName, Rep.LastNameFROM OrdersINNER JOIN CustomerON Orders.Customer_Num=Customer.CustomerNumINNER JOIN RepOn Customer.Rep_Num = Rep.Rep_NumWHERE Orders.Order_Num = 21610 |
|
|
wormz666
Posting Yak Master
110 Posts |
Posted - 2008-10-15 : 21:39:28
|
SELECT Customer.CustomerName, Rep.FirstName, Rep.LastNameFROM OrdersINNER JOIN (Customer INNER JOIN RepOn Customer.Rep_Num = Rep.Rep_Num) ON Orders.Customer_Num=Customer.CustomerNumWHERE Orders.Order_Num = 21610 |
|
|
jsweazy
Starting Member
3 Posts |
Posted - 2008-10-15 : 22:46:43
|
quote: Originally posted by wormz666 SELECT Customer.CustomerName, Rep.FirstName, Rep.LastNameFROM OrdersINNER JOIN (Customer INNER JOIN RepOn Customer.Rep_Num = Rep.Rep_Num) ON Orders.Customer_Num=Customer.CustomerNumWHERE Orders.Order_Num = 21610
Is that the best way to type it? |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-10-16 : 02:44:24
|
no, you did it right your own wayEm |
|
|
|
|
|
|
|