gpt4 book ai didi

MySql Union 仅从 BOTH 返回值

转载 作者:行者123 更新时间:2023-11-29 13:57:57 25 4
gpt4 key购买 nike

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)

结果

| NAME |--------|  Zac |

See the demo

关于MySql Union 仅从 BOTH 返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15530369/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com