gpt4 book ai didi

MySQL 多表连接

转载 作者:可可西里 更新时间:2023-11-01 07:57:50 26 4
gpt4 key购买 nike

我需要修改以下 MySQL 语句以包含来自第三个表的信息...但我不擅长连接。

select
ss.*,
se.name as engine,
ss.last_run_at + interval ss.refresh_frequency day as next_run_at,
se.logo_name
from
searches ss join search_engines se on ss.engine_id = se.id
where
ss.user_id='.$user_id.'
group by ss.id
order by ss.project_id, ss.domain, ss.keywords

我还需要通过将 searches.project_idprojects.id 匹配来检索 projects.project_name

最佳答案

查看 SELECT SyntaxJOIN Syntax .

但是,最简单的答案——添加另一个 JOIN..ON 语句。

select
ss.*,
se.name as engine,
ss.last_run_at + interval ss.refresh_frequency day as next_run_at,
se.logo_name,
pr.project_name -- +
from
searches ss
join search_engines se on ss.engine_id = se.id
join projects pr on ss.project_id = pr.id -- +
where
ss.user_id='.$user_id.'
group by ss.id
order by ss.project_id, ss.domain, ss.keywords

[EDIT] 我添加了 -- + 注释以指出我的添加。

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

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