1

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.

4 Answers 4

2

If you want to do partial matches you need the LIKE operator:

SELECT * FROM table WHERE type LIKE 'Test%'
Sign up to request clarification or add additional context in comments.

2 Comments

%Test ends with Test and not starts with it.
@JacquesAmar Corrected.
1

Use the Like keyword

select * from table where type LIKE 'Test%'

Comments

1

The equality (=) operator doesn't accept wild cards. You should use the like operator instead:

SELECT * FROM table WHERE type LIKE 'Test%'

Comments

1

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%'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.