Reputation: 768
I have two tables, vendors
and customers
, with the following fields:
vendors:
vendor_id name UUID
--------- -------------- ---------------
1 V1 vendor 01ffd02
2 V2 vendor 02daaa2
3 V3 vendor 41ddasa
customer:
customer_id name UUID
--------- -------------- ---------------
1 cust1 71ffd02
2 cust2 92daaa2
3 cust3 11ddasa
The UUIDs above are not foreign keys, and not unique for both the tables.
I have to write a single query to capture all rows in either table with a given UUID. For example, if UUID = '11ddasa'
, the result should be the last row in customer
above.
Upvotes: 0
Views: 48
Reputation: 586
Is this what you're looking for?
SELECT name,UUID from vendors where UUID='11ddasa'
UNION
SELECT name,UUID from customer where UUID='11ddasa'
This will return all rows from either table with UUID.
Upvotes: 0
Reputation: 425623
SELECT *
FROM vendors
WHERE uuid = '11ddasa'
UNION ALL
SELECT *
FROM customers
WHERE uuid = '11ddasa'
Upvotes: 1