php+mysql数据查询技巧

WBOY
Release: 2016-06-06 20:17:27
Original
1176 people have browsed it

某表,有cat_id字段,查询时候,

cat_id=1,找出5条记录,
cat_id=2,找出5条,
cat_id=3,找出5条,
......
cat_id=n,找出5条
......

这样的查询要求,
除了循环select, 有没有高效点的做法?

回复内容:

某表,有cat_id字段,查询时候,

cat_id=1,找出5条记录,
cat_id=2,找出5条,
cat_id=3,找出5条,
......
cat_id=n,找出5条
......

这样的查询要求,
除了循环select, 有没有高效点的做法?

你想查的是什么呢?是记录条数,还是记录的某些字段?

group by cat_id可以
cat_id in()也可以

循环select肯定行不通,这样性能太差,可以order by cat_id,这样结果对cat_id来说有序,
然后对结果做一下map,cat_id相同的放在一个map里面

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template