How to look for similar words inside a text field in MySQL?

by RoyBarOn   Last Updated August 13, 2019 22:26 PM

I have a table names Users, each user has hobbies inside Hobbies field. I want to find users with matching hobbies,

The hobbies are stored like this:

id | username | hobbies
 1 | Ben      | Hiking, Surfing
 2 | Jane     | Surfing,
 3 | Dan      | Reading

I want to sort the table by the matching user's hobbies - so the result will be something like :

HobbieName (Hiking) | id | username
                    | 1  | Ben
                    | 2  | Jane

Is it possible to do with MySql query or should I sort the data by PHP ?

Tags : php mysql


Answers 1


SELECT *
FROM `Hobbies` 
WHERE `hobbies` LIKE `%Hiking%`
ORDER BY `id` DESC ;

Hobbies is your table. hobbies is your column in Hobbies table. LIKE try to get all result contains the text %Hiking% will search for any world contain Hiking like these examples :

First Hiking

My Hiking is

Hiking is best

GameO7er
GameO7er
August 13, 2019 22:23 PM

Related Questions


Updated March 19, 2019 12:26 PM

Updated October 14, 2017 00:26 AM

Updated July 28, 2019 21:26 PM

Updated October 16, 2017 06:26 AM