HakunaMatata
HakunaMatata

Reputation: 87

What is the correct mysql query which searches for fields containing forward slashes?

I have to write a query which checks for a field "zone" and its value in one of the rows is "inter/intra". I need to query this field to retrieve its value. Something like

select id from table where zone = 'inter/intra'

OR

select id from table where zone like 'inter/intra'

However this query is failing everytime.

Please tell me the right query for this.

Upvotes: 0

Views: 43

Answers (1)

Keith
Keith

Reputation: 738

When you use like, you need to add wildcards: the % symbol represents any arbitrary string. For example this will find the id of the record where zone contains "inter/intra":

select id from table where zone like '%inter/intra%'

This will find the id of the record where zone starts with "inter/intra":

select id from table where zone like 'inter/intra%'

This will find the id of the record where zone ends with "inter/intra":

select id from table where zone like '%inter/intra'

Upvotes: 2

Related Questions