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 |
|
jjwest
Starting Member
2 Posts |
Posted - 2012-04-11 : 20:03:53
|
| i have a query in which i have to return OrderID, OrderDate and ShipCity for all orders where the customers city is Toronto The orders table has PK OrderID, OrderDate and ShipCity etc in it and has FK CustomerID and the Customer table has PK CustomerID City etcThis is the code i have come up withSelect OrderID, OrderDate, ShipCityFrom OrdersWHERE Orders.CustomerID = Customer.CustomerID AND Customer.City = ‘Toronto’Any help would be appreciated |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-04-11 : 20:47:54
|
You have to also include Customer table in the FROM clause. I prefer to use explicit join statements rather than the old ANSI style joins, so your query would be something like this:SELECT o.OrderID, o.OrderDate, o.ShipCityFROM Orders o INNER JOIN Customers c ON o.CustomerID = c.CustomerIDWHERE c.Customer.City = 'Toronto' |
 |
|
|
jjwest
Starting Member
2 Posts |
Posted - 2012-04-11 : 20:54:13
|
| thanks this way is alot clearer |
 |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-04-12 : 19:40:39
|
You are welcome - but now that I am looking at it, I am surprised it worked; I assume you changed it toWHERE c.Customer.City = 'Toronto' |
 |
|
|
|
|
|