Damjan Pavlica Damjan Pavlica - 1 year ago 71
SQL Question

SQL query to find all words starting with the exact phrase?

I have many books in the MySQL database. And I am looking for the specific headers. I know how to find every header string that begin with the word "dan":

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

But how to find words in the header that begins with phrase "dan"?

Thanks in advance.

Answer Source

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%';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download