Skip to content
Advertisement

How to select titles that are like the first n characters of a string?

Here’s an example

There are titles of some animes:

And I’d like to select those titles, that contain the first 10 character of the first record, so “My Hero Academia” in this example

It’s important that it must be the first N characters, like 10,15,20. So SELECT title FROM tablename WHERE title LIKE "%My hero Academia%" is not the solution I’m looking for.

Also: this is just an example,there are many other titles too, and I don’t always know what the first 10 characters are. So I also can’t simply put the first 10 characters of “My hero academia” in the WHERE title LIKE clause.

I mean something like this:

Is there a way to do that with SQL?

Advertisement

Answer

for filter a string for a partial fixed value you can use like operator like 'yourstring%' eg:

or use a string fuction like substr or left

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement