I have these tables:
Customer Details
CustCode, Name , Address, CityID
MasterCity
CityName, CityId
OrderDetails
OrderDetails, CustCode , OrderNo, Somedetails , DeliveryStation
Deliverystation is that where order has to be placed. Here I send CityId
and Customer Details also contains CityId and not cityname.
Now I want to select data from OrderDetails. I join OrderDetails and Customer Details On Customer Details.CustCode = OrderDetails.CustCode and Customer Details and MasterCity on MasterCity.CityId = Customer Details.CityId.
this work fine but i also want to join OrderDetails and MasterCity to get DeliveryStation City Name.
How can I do this?
Just add another join to MasterCity with an alias, eg
Select a.CustCode, a.Name, a.Address, A.CityId,c.OrderNo, c.SomeDetails,d.CityName DeliveryStation
from CustomerDetails a
join MasterCity b
on a.CityID=b.CityID
join OrderDetail c
on a.CustCode=c.CustCode
join MasterCity d
on d.CityId=c.DeliveryStation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With