Reputation: 72
I face some problems here and i need any helps
this is my table
TableA
uomid | uomname
1 KG
2 Gram
TableB
id | itemname | uomid1 | uomid2
1 Corn 1 2
What i hope for result is
id | itemname | uomname1 | uomname2
1 Corn KG Gram
Thanks for any helps
Upvotes: 0
Views: 31
Reputation: 18747
You need to join TableA twice with different alias names.
SELECT B.id,B.itemname,A1.uomname as uomname1,A2.uomname as uomname2
FROM TableB B JOIN
TableA A1 ON A1.uomid=B.uomid1 JOIN
TableA A2 ON A2.uomid=B.uomid2
Result:
ID ITEMNAME UOMNAME1 UOMNAME2
------------------------------------
1 Corn KG Gram
See result in SQL Fiddle.
Upvotes: 2