James Arnold
James Arnold

Reputation: 780

MySQL Exclude Over Include in FIND_IN_SET()

For example, I have a table like this:

----------------------------------------------------------------------------
|   id     |    title     |                        tags                    |
----------------------------------------------------------------------------
|    1     | Title 1      |  funny, adventure                              |
----------------------------------------------------------------------------
|    2     | Title Two    |  funny, short, horror                          |
----------------------------------------------------------------------------
|    3     | Title III    |  funny, short, adventure                       |
----------------------------------------------------------------------------

How can I query that I want to include funny or short but exclude horror in the results? Like the exclude will overpower even if one of its include criteria matches?

----------------------------------------------------------------------------
|   id     |    title     |                        tags                    |
----------------------------------------------------------------------------
|    1     | Title 1      |  funny, adventure                              |
----------------------------------------------------------------------------
|    3     | Title III    |  funny, short, adventure                       |
----------------------------------------------------------------------------

Upvotes: 1

Views: 488

Answers (1)

phpforcoders
phpforcoders

Reputation: 326

Try this -

SELECT * FROM table_name WHERE NOT find_in_set('horror',tags) <> 0 

Upvotes: 1

Related Questions