1

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

3
  • Are the tags part of the question? or a separate field? Commented Jul 25, 2014 at 10:12
  • Post a sample question with tag included in it Commented Jul 25, 2014 at 10:12
  • tegs are part of question Commented Jul 25, 2014 at 10:14

4 Answers 4

3
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:]'
Sign up to request clarification or add additional context in comments.

5 Comments

If the start tag is of format '[en]' and end tag is of format '[en:]', then > The question states: I want to select only that questions which have [en] [en:] and [hi][hi:] tags in mysql
I added [en] as one example. I know that there exists other formats like [hi]. See my answer as well
Point is that your query in your answer matches questions that have either [en]foo[en:] or [hi]bar[hi:]. Rahul wants to match questions that have both. For example [en]foo[en:] [xx]whoop![xx:] [hi]bar[hi:] should match but not [en]foo[en:] [xx]whoop![xx:] (at least: that's how I understand the question)
I am not sure if the same row contains both versions of questions in the same column. OP though claims in the same column, I fear it is not same row.
Ah that would make (a bit :P ) more sense. Also: did you 'miss' the wildcard(s) at the end of your second queries on purpose? Shouldn't like '%[en]%[en:]' or ... be like '%[en]%[en:]%' or ...? If OP could clarify the data in the table a like '[en]%[en:]' or... might even suffice which might actually even use indexes...
2
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.

Comments

0

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

3 Comments

Nonsense; INNODB supports LIKE queries just as well as MyISAM.
Ye true, i made a mistake i mean full text search
INNODB supports full text search just as well (just like MyISAM). Also adding another column like you suggest is NOT the way to go. OP needs to add a column 'language_id' and add another table with languages and use FK's like they're intended to.
0

I found this to work

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.