Reputation: 11
Any help is much appreciated.
I'm using this query right now.
SELECT t.itemID, RepID, InsRepairID
FROM tbl_item t
left join tbl_insiderepair i on i.itemID = t.itemID
left join tbl_underrepair u on u.itemID = t.itemID
where(i.itemID = t.itemID Or u.itemID = t.itemID);
This is the result.
itemID | RepID | InsRepairID
1 3 null
2 null 1
3 null 2
Now I want to make 'RepID and InsRepairID columns' (they're ID's from different tables) into ONE column.
Upvotes: 1
Views: 29
Reputation: 10555
SELECT t.itemID, COALESCE(RepID, InsRepairID)
FROM tbl_item t
left join tbl_insiderepair i on i.itemID = t.itemID
left join tbl_underrepair u on u.itemID = t.itemID
where(i.itemID = t.itemID Or u.itemID = t.itemID);
Upvotes: 0
Reputation:
By Using Union You add Two Tables Show In One Column
Select itemID, RepID from tbl_item
union
SELECT itemID,InsRepairID from tbl_insiderepair
Upvotes: 1
Reputation: 3541
You could use ifnull sql function, like this:
SELECT t.itemID, IFNULL(RepID, InsRepairID) ID
FROM tbl_item t
left join tbl_insiderepair i on i.itemID = t.itemID
left join tbl_underrepair u on u.itemID = t.itemID
Upvotes: 0