If i'm not wrong when using having, the query is executed without any filters then the code go over all the result to apply the filter. But in this case I'm using multiple Like//If to calculate my order. I was wondering what would be better between:
SELECT Page.*,
if (`flags` LIKE CONCAT('%',?,'%'),
if (`title` LIKE CONCAT('%',?,'%'),
5,
3
),
if (`title` LIKE CONCAT('%',?,'%'),
2,
0
),
) as pageOrder
FROM Page
WHERE `flags` LIKE CONCAT('%',?,'%') OR `title` LIKE CONCAT('%',?,'%')
ORDER BY pageOrder DESC
or
SELECT Page.*,
if (`flags` LIKE CONCAT('%',?,'%'),
if (`title` LIKE CONCAT('%',?,'%'),
5,
3
),
if (`title` LIKE CONCAT('%',?,'%'),
2,
0
),
) as pageOrder
FROM Page
HAVING pageOrder > 0
ORDER BY pageOrder DESC
using mysql 5.7 and php 7.1