我需要修改以下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
我还需要通过将projects.project_name
与searches.project_id
匹配来检索projects.id
。
答案 0 :(得分:6)
但是,最简单的答案 - 添加另一个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
[编辑]我添加了-- +
条评论以指出我的添加内容。