Click here to Skip to main content
15,901,284 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i am having to table 1st one city_master and 2nd Transaction

City_Master

id City
1 Nagpur
2 Mumbai
3 Pune

Transcation

id Supplier_name Product Qty City Alt_City
1 Nikhil Iron 100 1 2
2 Amit Copper 100 1 3
3 Rohit Steel 100 3 1

i want query output like below

1 Nikhil Iron 100 Nagpur Mumbai
2 Amit Copper 100 Nagpur Pune
3 Rohit Steel 100 Pune Nagpur
Posted
Updated 19-Jul-13 21:59pm
v2
Comments
MuhammadUSman1 20-Jul-13 3:54am    
You should join on the base of Alt_City from Transaction table and ID from City_Master Table.
check my solution

it will give your Expected output

To select All Columns
SQL
Select * from transaction t
join City_Master cm on t.Alt_City=cm.id


For selected Columns

SQL
Select t.Supplier_Name,t.Product,t.Qty,cm.City from transaction t
join City_Master cm on t.Alt_City=cm.id


for more info about join please visit this link
 
Share this answer
 
v3
hi friend,

Try This...


SQL
Select T0.id, T0.Supplier_name, T0.Product, T0.Qty ,(select A.City from City_Master A.id=T0.City) as 'City', (select A.City from City_Master A.id=T0.Alt_City) as 'Alt_City' from Transcation T0




Happy Coding :)
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900