Rafa Tost
Rafa Tost

Reputation: 399

how do i text search multiple columns in mysql and order by columns?

I am searching columns A,B,C for the word 'hello'.

I want the results to be returned in order of columns being searched..

EG return all column a results, then column b, then column c.

is this possible? I am doing this currently.

SELECT * FROM `table` where table.A LIKE "%hello%" OR table.B LIKE "%hello%" OR table.C LIKE "%hello%"

Upvotes: 0

Views: 25

Answers (1)

Raging Bull
Raging Bull

Reputation: 18747

Use UNION:

SELECT * FROM `table` where A LIKE "%hello%" 
UNION
SELECT * FROM `table` where B LIKE "%hello%"
UNION
SELECT * FROM `table` where C LIKE "%hello%"

Upvotes: 2

Related Questions