1

I am working on a small relational database for school and having trouble with a simple query. I am supposed to find all records in a table that have a field with the word 'OMG' somewhere in the text. I have tried a few other and I can't figure it out. I am getting an invalid relational operator error.

my attempts:

select * from comments where contains('omg');
select * from comments where text contains('omg');
select * from comments where about('omg');

and several more variations of the above. As you can see I am brand spanking new to SQL. text is the name of the field in the comments table.

Thanks for any help.

1

2 Answers 2

1

Assuming that the column name is text:

select * from comments where text like '%omg%';

The percentage % is a wild-card which means that any text can come before/after omg

Pay attention, if you don't want the results to contain words in which omg` is a substring - you might want to consider adding whitespaces:

select * from comments where text like '% omg %';

Of course that it doesn't cover cases like:

  • omg is at the end of the sentence (followed by a ".")
  • omg has "!" right afterwards
  • etc
Sign up to request clarification or add additional context in comments.

Comments

1

You may want to use the LIKE operator with wildcards (%):

SELECT * FROM comments WHERE text LIKE '%omg%';

2 Comments

ans this answer is different than mine cause ?
Nope, not much different. We just hit it around the same time -- no harm no foul. Yours has a description of what a wildcard does. Mine has a link to LIKE documentation, so I'll leave it for reference.

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.