本文介绍了MySQL多表联接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要修改以下MySQL语句以包含来自第三张表的信息...但是我很迷恋联接.
I need to modify the following MySQL statement to include information from a third table... but I suck at joins.
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_id
与projects.id
匹配来检索projects.project_name
.
I need to also include retrieving projects.project_name
by matching searches.project_id
to projects.id
.
推荐答案
Check out SELECT
Syntax and JOIN
Syntax.
但是,最简单的答案-添加另一个JOIN..ON
语句.
But, simplest answer -- add another JOIN..ON
statement.
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] I added the -- +
comments to point out my additions.
这篇关于MySQL多表联接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!