Rahul Gahlot
Rahul Gahlot

Reputation: 71

select values which contains specific characters in mysql

I have a database table which contains questions in hindi and english language in same column but are separated by keyword [en] english language [en:] and [hi] hindi language [hi:] and some of them are not separated by language tags

I want to select only that questions which have [en] [en:] and [hi][hi:] tags in mysql

Upvotes: 1

Views: 4638

Answers (4)

billyl320
billyl320

Reputation: 62

I found this to work

Select * from table_name
       where question like '%en%' 

Upvotes: 0

user956584
user956584

Reputation: 5558

Add another column eq enum type EN => [Y,N] HI [Y,N], you can use query like in other questions to update database. So its more optimal that use like search every time

Upvotes: 0

Ravinder Reddy
Ravinder Reddy

Reputation: 24012

Select * from table_name
 where question like '%[en]%' or 
       question like '%[en:]%' or 
       question like '%[hi]%' or 
       question like '%[hi:]%'

If the start tag is of format '[en]' and end tag is of format '[en:]', then

Select * from table_name
 where question like '%[en]%[en:]' or 
       question like '%[hi]%[hi:]'

Upvotes: 3

RobIII
RobIII

Reputation: 8821

Select *
From mytable
Where mycolumn like '%[en]%[en:]%'
    and mycolumn like '%[hi]%[hi:]%'

Note that this query will not be very performant but that's what you get for not normalizing your database.

You could use a regex match to ensure not finding 'tags' that contain other tags like [en]foo[hi]bar[en:] but that would make performance even worse.

Upvotes: 2

Related Questions