Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I've a table named comments where comment is a field where comment will be stored.

Now I want to find -1 within that comment.

the -1 should be independent. That is, it should not be joined with other word like 2-1.

I just want to know whether a comment contains -1.

I'm currently using where instr(comment,' -1 ') != 0.

I want this because, users can downvote a post by commenting with -1

Any ideas on how to do this even more efficiently.

I'm using MySql 5.1, if that helps.

Summary:

I want to select all rows that contain -1

share|improve this question
    
I think you have bad db design,downvotes should be stored in a int or tinyint column.Maybe create a trigger which will update a new column based on your actual results and query that. –  Mihai Feb 18 at 15:37
    
@Mihai, I don't have any table itself. I'm just quering the data. I'm not storing it explicitly. –  Amit Joki Feb 18 at 15:44
    
If the data is pre-existing in the database there is no way that is more efficient. If at all possible you should strongly consider pre-parsing the comment when it is created and storing the value then as an int as Mihai suggested. This could also be done as an index on the table at a stretch. –  Zack Feb 18 at 21:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.