Multiple like in sql Query performance



1.07 K Views | Rishi Kashyap | 1
Rishi Kashyap
8.72 K
X

Multiple like in sql Query performance


0

Multiple like in sql query may slow down performance if not properly done !

Was using the below sql query in PHPSELECT DISTINCT col.id,name FROM col,cor WHERE seat.id=col.id AND seat.id='$sql_id' AND name LIKE '%$like%' OR desc LIKE '%$like%' ORDER BY name LIMIT 0,100I was using 2 like in my sql query and the query was taking exceptional long time to execute.

Simple use of parentheses "()" solved the problem, modified sql query looked likeSELECT DISTINCT col.id,name FROM col,cor WHERE (seat.id=col.id AND seat.id='$sql_id') AND (name LIKE '%$like%' OR desc LIKE '%$like%') ORDER BY name LIMIT 0,100
This improved the performance. Probably the use of Multiple like confuses the execution of the query and adding parentheses makes it more clear.

Rishi Kashyap | | EDIT | REPLY


tags  MYSQL TUTORIAL PHP TUTORIAL

SUBSCRIBE TO RISHI'S BLOGS

SHARE Whatsapp Facebook Twitter To TOP