Thu Nguyen
Thu Nguyen

Reputation: 21

Mysql how to orderby matching query string with Full-Text Searches MATCH AGAINST

Ex I have table:

Id Name
1  bcd def abc
2  def abc
3  abc

I search by Boolean Full-Text Searches like

SELECT * FROM table WHERE MATCH (name) AGAINST ('abc*' IN BOOLEAN MODE)

how to order by if abc is first of text result order like this:

Id Name
1  abc
2  def abc
3  bcd def abc

if 'abc' postion is not a head will be pushed down

Upvotes: 1

Views: 38

Answers (2)

Rakesh Jakhar
Rakesh Jakhar

Reputation: 6388

You can use

ORDER BY LENGTH(`name`) ASC

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1271231

You can use locate():

order by locate('abc', name)

Upvotes: 1

Related Questions