【发布时间】:2016-01-19 14:24:09
【问题描述】:
我有一个名为 users 的表,其中包含用户 ID,以及一些表,如 cloud_storage_a、cloud_storage_b 和 cloud_storage_c。如果cloud_storage_a 中存在用户,则表示他们已连接到云存储 a。用户也可以存在于许多云存储中。这是一个例子:
users表:
user_id | address | name
-------------------------------
123 | 23 Oak Ave | Melissa
333 | 18 Robson Rd | Steve
421 | 95 Ottawa St | Helen
555 | 12 Highland | Amit
192 | 39 Anchor Rd | Oliver
cloud_storage_a:
user_id
-------
421
333
cloud_storage_b:
user_id
-------
555
cloud_storage_c:
user_id
-------
192
555
等等
我想创建一个查询来获取连接到任何云存储上的所有用户。所以对于这个例子,应该返回用户421, 333, 555, 192。我猜这是某种加入,但我不确定是哪一种。
【问题讨论】:
标签: sql postgresql join distinct exists