Skip to content
Advertisement

How to sort an mysql Result?

Table :

JavaScript

Question

string: $#

JavaScript

Result Order

JavaScript

I have no idea how to achive the order list by how many words are matched in string.

It will be great if you explain the query.

Thank you.

Advertisement

Answer

Convert your string to JSON array then

JavaScript

@criteria is a placeholder for JSON array mentioned above.

Of course, you may provide your criteria as space-separated string and convert it to JSON in the query using string functions.


The version without JSON usage:

JavaScript

https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=3ab611ed7429e23be2abfcb8b0186e6d

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement