开发者

get categories from a limited query

i have the following query:

select company_title,address,zipcode.zipcode,city,region,category from test.companies
left join test.address on companies.address_id = address.address_id
left join test.zipcode on companies.zipcode_id = zipcode.zipcode
left join test.categories on companies.category_id = categories.category_id
where company_title like '%gge%'
limit 10;

as you see, each company has a category. i was wondering if i can get a list of the categories (from the total results, not the limited one) just as CALC F开发者_JS百科OUND ROWS does?


Nope, you are asking for a totaly different set of data here, you can only do another query or process this with your application code by preloading all data and counting the distincts in memory. If your dataset is big, then i'd recommend using a second query, mysql can support 1 more query easy, but working with 100 000 rows to count the distinct and preload everything is usually not the wiser choice :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜