gpt4 book ai didi

php - 从多个表中选择多行

转载 作者:行者123 更新时间:2023-11-28 23:12:18 25 4
gpt4 key购买 nike

表 1

 id  | name | can  | some
---- +------+------+-----
1 |A | can1 | f
2 |B | can0 | g
3 |C | can1 | h
4 |d | can2 | i

表2

id  | name | description
----+------+--------------
1 |can0 | some text
2 |can1 | another text
3 |can2 | text to

我有两张 table 。我想从 table1 获取行 id=3 并获取 can1description > 来自 table2

我试过了

SELECT t1.* , t2.description 
from table1 as t1 , table2 as t2
WHERE t1.can = t2.name

但这行不通。请帮忙谢谢

最佳答案

维护第二个表的id而不是text

表:- T1

id  | name | can    | can_id
---- +------+-------+--------
1 |A | can1 | 2
2 |B | can0 | 1
3 |C | can1 | 2

表:- T2

id  | name | description
----+------+--------------
1 |can0 | some text
2 |can1 | another text
3 |can2 | text to

查询不维护ID O表T2

select t1.*,t2.* from T1 as t1 join T2 as t2 on t1.can = t2.name

带身份证

select  t1.*,t2.* from T1 as t1 join T2 as t2 on t1.can_id = t2.id

关于php - 从多个表中选择多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45409776/

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