如何在没有union的情况下优化以下查询顺序

时间:2018-01-18 09:47:14

标签: mysql

我需要一个逻辑来根据字符串搜索列。

考虑以下查询。在下面的查询中,我想在customer表中搜索字符串'test'。如果在客户名称列中找到它,则需要位于顶部,然后是基于customer_slug找到的列

SELECT * FROM `customer_list` WHERE customer_name = 'test' UNION
SELECT * FROM `customer_list` WHERE customer_slug = 'test'

2 个答案:

答案 0 :(得分:1)

SELECT * FROM customer_list 
where 'test' in (customer_name, customer_slug)
order by 'test' <> customer_name,
         'test' <> customer_slug

答案 1 :(得分:0)

"URL with ' "