Here is my query
select t1.*, t2.name as customer, t2.name as vendor from order t1
left join contact t2
on t2.id = t1.cid and t2.id = t1.vendid
where t1.id = 22
- contact_Table => id, Name
- order_Table => id, orderName, cid, vendid
My problem is I want to select an order where order.id = 22 and instead of order.cid, order.vendid I want their names which exist in contact table.
Above query result with customer = vendor = NULL
Ok. The query will result with customer=vendor=null because you are setting
t2.id = t1.cid and t2.id=t1.vendid, or t2.id=t1.cid=t1.vendid. Since I guess no order has the same vendor and customer ID, your query wont work.Try this:
This way you link twice with the contacts table, one of them to get the customer info and one to get the vendor info.