gpt4 book ai didi

MySQL 按 ID 连接 2 个表

转载 作者:行者123 更新时间:2023-11-29 23:52:06 24 4
gpt4 key购买 nike

在我的“球队”表中,我有球员的唯一 ID(player_1、player_2、player_3、player_4、player_5),在我的“球员”表中,这些 ID 指的是球员的姓名。例如,在搜索脚本案例中(按名称搜索):

The user write "foo" but "foo" is ID 20.

"teams" ID 1 => player_1 ID = 20
"players" player_id = 20 > name = foo

这是我的查询:

$sql = 'SELECT * FROM teams LEFT JOIN players ON players.name LIKE :word';

但是它没有像我想要的那样工作......

最佳答案

尝试以下查询

select * from teams as tm,players as py where tm.player_1=py.player_id and py.name LIKE 'foo%'

为什么需要加入团队表?您可以使用玩家表仅按名称进行搜索。

关于MySQL 按 ID 连接 2 个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25580565/

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