sql - How to optimize the count query for each categories for the search results? -


i have 9 categories classfieds website. when user search keyword, want show search results , number of search results in each of categories.

how optimize sql query?

what have tried? run loop each category:

select * ads title '%keyword%'; select count(*) ads title '%keyword%' , category_id = 1; select count(*) ads title '%keyword%' , category_id = 2; select count(*) ads title '%keyword%' , category_id = 3; select count(*) ads title '%keyword%' , category_id = 4; ..... 

any better suggetions make sql queries faster?

use group clause

select    count(*)    ,category_id      ads      title '%keyword%'  group category_id 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -