What I currently have selects based on a column having the same value..
"SELECT * FROM users WHERE uuid = ?"
But what if I want to return a row based on one of the columns "containing" a string value? Some pseudo code would be:
SELECT * FROM users
WHERE column CONTAINS mystring
Any help is appreciated, I have been searching for other answers but to no avail.
SELECT * FROM users WHERE column LIKE '%mystring%'
will do it.
LIKE
means we're not doing an exact match (column = value
), but doing some more fuzzy matching. "%" is a wildcard character - it matches 0 or more characters, so this is saying "all rows where the column has 0 or more chars followed by "mystring" followed by 0 or more chars".
Use LIKE
clause.
E.g. if your string contains "pineapple123"
, your query would be:
SELECT * from users WHERE column LIKE 'pineapple%';
And if your string always starts with any number and ends with any number like "345pineapple4565"
, you can use:
SELECT * from users WHERE column LIKE "%pineapple%";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With