How can I select a row specific by string values
SELECT * FROM my_table WHERE name=
-- then some function to test what string it starts with
Its a bit hard to explain so i will explain an example with JavaScript
if(mystring.inde开发者_JS百科xOf('targetstring') != -1){
// if that variable contains this string
}
if(mystring.indexOf('targetstring') == 0){
// if that variable starts with this string
}
So all in all, I want to select rows, when their name(a string column) starts with or contains a specific string.
You can use LIKE
and the wildcard %
:
SELECT * FROM my_table WHERE name LIKE 'john%'; /* name starts with john*/
SELECT * FROM my_table WHERE name LIKE '%john%'; /* name contains john*/
SELECT * FROM my_table WHERE name like "%string%"
精彩评论