mySQL search query

 mySQL search query on multiple columns with a single parameter.


set @search='32' ;


select DISTINCT p.id as product_id, p.name as title, p.sku, p.description, 

   p.material,c.name as color, ct.name as category from 

products p

inner join color_product cp on p.id=cp.product_id

inner join colors c on cp.color_id=c.id

inner join categories ct on p.category_id=ct.id

where p.name  LIKE CONCAT("%",@search,"%") OR

  p.sku  LIKE CONCAT("%",@search,"%") OR

      p.description  LIKE CONCAT("%",@search,"%") OR

      p.material  LIKE CONCAT("%",@search,"%") OR

      c.name   LIKE CONCAT("%",@search,"%") OR

      ct.name   LIKE CONCAT("%",@search,"%") ;


Comments

Popular posts from this blog

TSQL To Get All the Names of tables and Databases whose data have changed in last 24 Hours

To Get All the Names of tables and Databases their data have changed in last 24 Hours And Backup those databases

Apply paging in procedure