查询1:
SELECT * FROM `games` WHERE `title` LIKE '%{$search}%'
查询2:
SELECT * FROM `games` WHERE `tags` LIKE '%{$search}%'
我想在这样的一个中获得两个查询:
SELECT * FROM `games` WHERE `title` LIKE '%{$search}%' then `tags` LIKE '%{$search}%'
我获得Title =搜索词的游戏的搜索结果优先级First, 然后显示标签=搜索词的不太重要的结果。
怎么做?
答案 0 :(得分:1)
在case
中设置ORDER BY
表达式,以便首先返回标题:
SELECT *
FROM `games`
WHERE `title` LIKE '%{$search}%' OR `tags` LIKE '%{$search}%'
ORDER BY case when `title` LIKE '%{$search}%' then 0 else 1 end