0

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.

Henry Keiter
  • 16,863
  • 7
  • 51
  • 80
user3189916
  • 758
  • 1
  • 7
  • 26

2 Answers2

1
SELECT  *
FROM    vendors
WHERE   uuid = '11ddasa'
UNION ALL
SELECT  *
FROM    customers
WHERE   uuid = '11ddasa'
Quassnoi
  • 413,100
  • 91
  • 616
  • 614
0

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.

Jim
  • 576
  • 2
  • 11