Reputation: 181
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.
Upvotes: 1
Views: 78
Reputation: 53565
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:
Upvotes: 1
Reputation: 29198
You may want to use the LIKE
operator with wildcards (%):
SELECT * FROM comments WHERE text LIKE '%omg%';
Upvotes: 1