Reputation: 5480
I have a table in mysql
with column called type
. contents are below
Type
Test 12
Test abc
start 1
start abcd
end 123
Now I want to select records where type
starts with Test
Expected result:
Test 12
Test abc
But I am getting either
Test 12 or empty results
I have tried like below:
select * from table where type = 'Test 12'
select * from table where type = '%Test%'
select * from table where type = '%Test'
What should be the correct sql
statement.
Upvotes: 1
Views: 237
Reputation: 211680
If you want to do partial matches you need the LIKE
operator:
SELECT * FROM table WHERE type LIKE 'Test%'
Upvotes: 2
Reputation: 1833
Sooo close! You want to start with the string, then don't use % in the start, and use LIKE
instead of =
select * from table where type LIKE 'Test%'
Upvotes: 1
Reputation: 311883
The equality (=
) operator doesn't accept wild cards. You should use the like
operator instead:
SELECT * FROM table WHERE type LIKE 'Test%'
Upvotes: 1