0

So I am starting SQL and I have the following query

Select * from Material where theme = 'math' or name = 'math';

As far as I know this gets me the values that actually have that exact string 'math' on the theme or on the name. How do I put it if I want that value i.e 'math' also as a substring of the attributes theme or name.

1

2 Answers 2

2

Simplest method is to use a wildcard match using the LIKE operator:

 WHERE theme LIKE '%math%'  // math appears anywhere in the string
 WHERE theme LIKE 'math%'   // math appears at the START of the string
 WHERE theme LIKE '%math'   // math appears at the END of the string
Sign up to request clarification or add additional context in comments.

Comments

2
Select * from Material where theme LIKE '%math%' or name LIKE '%math%';

I believe you are interested in using the LIKE operator.

2 Comments

Oh, thanks. I thought I had to use something like SUBSTRING();
Well you shouldn't look at it like substring, because you're not trying to extract a portion of a string. You are simply trying to match a portion of the string. Which is why LIKE is what you want oppose to substring

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.