My query:
SELECT * FROM CIUploads WHERE UploadTitle LIKE 'example'
Snapshot of the CIUploads Table:
Error, I'm expecting 20+ matches
MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0002 sec )
In order to get all records containing the word example in UploadTitle
, enclose the word within the wildcard %
like,
SELECT * FROM CIUploads WHERE UploadTitle LIKE '%example%'
Adding LIKE 'example'
(without wildcard) will return records which contain UploadTitle
as value example
only. In your table there are other words along with example
(eg: Video Example) and there are no records containing value exactly as example
. So it will return empty records.
For more details please refer this link.
To find records that :
starts with a => 'a%'
ends with b => '%b'
containing xyz => '%xyz%'
I assume you're expecting the given rows (UploadId 57, 58 ...) in the result set. So you should check whether or not you use a collation with case sensitivity.
If you are using a case sensitive collation, the correct query is
SELECT * FROM CIUploads WHERE UploadTitle LIKE '%Example%'
(with uppercase 'E' at the beginning of 'Example')
Some basics about LIKE -
% Wildcard - means anything can replace the % (can be a sentence)
WHERE UploadTitle like '%example' --The string ends with example
WHERE UploadTitle like 'example%' --The string starts with example
WHERE UploadTitle like '%example%' --The string contains example
WHERE UploadTitle like 'example' --The string equals to example
_ Wildcard - means any letter can replace the _ (only 1 letter)
WHERE UploadTitle like '__example' --the string has 2 letters before example
WHERE UploadTitle like 'example__' --the string has 2 letters after example
WHERE UploadTitle like '__example__' --the string has 2 letters before and after example
When no wildcard mentioned, it will be recognized as a string and will search for an exact match, so basically it equals to =
WHERE UploadTitle like 'example'
Same as:
WHERE UploadTitle = 'example'