Home  >  Article  >  Backend Development  >  求教一个基础的mysql多表联合查询的有关问题:怎么限制某张表中只查一条数据

求教一个基础的mysql多表联合查询的有关问题:怎么限制某张表中只查一条数据

WBOY
WBOYOriginal
2016-06-13 11:15:441277browse

求教一个基础的mysql多表联合查询的问题:如何限制某张表中只查一条数据
需求是这样的:从a表查图片,同时联合b表查图片的图片集名称,联合c表查图片的评论

现在只想得到从c表得到一条记录,该如何写?

现在的语句大概是这样的 select a.*,b.name,c.* from a as a left join b as b on a.pid =b.pid left join c as c on a.pid = c.pid where a.pid = XXX

但是这样查出来的结果是有多少条评论,就有多少条数据,该如何修改?

另求分析一条sql语句出来与查完A表用php foreach循环来查b c 再拼接到一起,效率相差大不大

只有20分了~~~

mysql join sql
------解决方案--------------------
limit 1不行吗
或者用group by c.主键
------解决方案--------------------
后面连上: group by c.pid 
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn