SQL – Find all words that start with some phrase


I have many books in my MySQL database. And I am looking for a specific words in my book headers. For example, I can find every header begins with the word "dan":

SELECT * FROM books WHERE header LIKE 'dan%';

But how to find a word inside the header that begins with the certain phrase?

Thanks in advance.


Here’s a quick and dirty trick: A word begins with dan can either be at the beginning of a header or after a space, so:

SELECT * FROM books WHERE header LIKE 'dan%' OR header like '% dan%';

Answered By – Mureinik

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published