nonochehe
nonochehe

Reputation: 11

MySQL - "exact match" against a value

I'm scratching my head on something and after a day of searching over the internet I've decided to ask you the question.

I got a table TAG with 2 fields tag_id and tag and I'm trying to match exactly the records of TAG against a particular string but I cannot make the match exactly, only partially. For instance I have 2 records in TAG:

tag = world
tag = world news

and I'm firing the following query:

Select tag,tag_id from TAG where match (tag) against ('Hello world')

And I would like only the taG "world" to be selected but both records are popping.

If I was firing

Select tag,tag_id from TAG where match (tag) against ('Hello world news')

I would like both records to pop.

Is there any way of achieving this? Thank you in advance :)

Upvotes: 0

Views: 863

Answers (2)

nonochehe
nonochehe

Reputation: 11

I think I actually found a way with LOCATE:

SELECT tag, LOCATE(tag, 'world news') from TAG where LOCATE(tag, 'world news') > 0

What do you think ?

Upvotes: 1

Amanjot
Amanjot

Reputation: 2048

To search anything in tag column that contains abc

Select tag,tag_id from TAG where tag like '%abc%'

To search in tag column that contains abc only i.e. only equals abc

 Select tag,tag_id from TAG where tag = 'abc'

Check the following link to compare strings https://www.w3schools.com/sql/sql_like.asp

Upvotes: 1

Related Questions