以下代码在Sequel Pro中正常运行,但是当我尝试使用PHP MySQLi运行它时,它没有做任何事情。这是解决我在多个列上搜索一个查询的问题的最佳方法吗?
非常感谢!
SELECT * FROM suppliers JOIN users on suppliers.user_id = users.id WHERE company_name LIKE '%hudd%'
UNION
SELECT * FROM suppliers JOIN users on suppliers.user_id = users.id WHERE additional_contacts LIKE '%hudd%'
UNION
SELECT * FROM suppliers JOIN users on suppliers.user_id = users.id WHERE company_number LIKE '%hudd%'
UNION
SELECT * FROM suppliers JOIN users on suppliers.user_id = users.id WHERE city LIKE '%lee%'
UNION
SELECT * FROM suppliers JOIN users on suppliers.user_id = users.id WHERE email LIKE '%miln.co%'
UNION
SELECT * FROM suppliers JOIN users on suppliers.user_id = users.id WHERE CONCAT_WS(" ", 'first_name', 'last_name') LIKE '%hudd%'
ORDER BY company_name
答案 0 :(得分:1)
你可以试试这个:
SELECT
DISTINCT *
FROM
suppliers
JOIN
users ON suppliers.user_id = users.id
WHERE
company_name LIKE '%hudd%'
OR additional_contacts LIKE '%hudd%'
OR company_number LIKE '%hudd%'
OR city LIKE '%lee%'
OR email LIKE '%miln.co%'
OR CONCAT_WS(' ', 'first_name', 'last_name') LIKE '%hudd%'
ORDER BY company_name
答案 1 :(得分:0)
SELECT * FROM test WHERE MATCH (column1,column2)
AGAINST ('+value1 +value2 +value3' IN BOOLEAN MODE);