Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Results 1 Zac Dave Ned Results 2 Eric Mark Zac
这是选择查询的输出。
select names from table where id=1 UNION select names from tables where id=2;
我想从两个结果中包含的这些结果中选择所有。Union 返回所有名称(Zac 只返回一次)。如何让查询只返回 Zac?
这应该这样做:
SELECT name FROM table1 INNER JOIN table2 USING (name)
结果
| 姓名 | -------- | 扎克 |
查看演示
只需INNER JOIN在两个表之间使用。
INNER JOIN
SELECT a.name FROM table1 AS a JOIN table2 AS b ON a.name = b.name