gpt4 book ai didi

sql - mysql 连接两个表

转载 作者:行者123 更新时间:2023-11-29 09:17:29 26 4
gpt4 key购买 nike

我在连接两个表时遇到问题:

table1    
id name
1 aaa
2 bbb
3 ccc

table2
id table1_id name
1 1 x1
2 1 x2
3 2 s1

table1 是主表,table2 包含属性。

我需要连接并搜索两个表,但显示与第一个表不同的结果。

使用JOIN时,我从table2获得多个结果。

场景是我需要搜索主表 TABLE1 和 TABLE2 中的所有属性,如果找到则返回

最佳答案

select distinct(name) from table1 inner join table2 on table1.id = table2.table1_id where table2.name = x2;

应该可以解决问题。

关于sql - mysql 连接两个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3634005/

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