Multiple like in sql Query performance




548 Views | Rishi Kashyap | 1 FOLLOW
    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 | 7 years ago | EDIT | REPLY



      tags  MYSQL TUTORIAL PHP TUTORIAL