我需要修改以下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
.
查看SELECT
语法和JOIN
语法.
但是,最简单的答案 - 添加另一个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
[ 编辑 ]我添加了-- +
评论以指出我的补充.