Reputation: 2369
I have a table named bills
having columns like bill_id, company_id,transaction_id
.
I run two queries :
"Select bill_id from bills where cmp_id = 1 ";
"Select bill_id from bills where cmp_id = 2";
Both queries return expected results separately. I require to output both columns of the two queries in a single select query. I tried using UNION/UNION ALL but i get repeated results or only a single column result
(select bill_id from bills where cmp_id =1 ) as cmp1Bills
union
(select bill_id from bills where cmp_id =2)as cmp2Bills order by bill_id;
Desired output:
cmp1Bills cmp2Bills
1 10
2 11
3 12
Upvotes: 0
Views: 36
Reputation: 51872
Use IN to include a group of values that can match the column for a row to be included
Select bill_id
from bills
where cmp_id IN (1, 2)
order by bill_id
Upvotes: 3