Search code examples
mysqlwildcardsql-like

MySQL searching for a keyword


I need to find all the plubisher names that contain the word AND. The teacher showed us his output file and it shows the following results:

#12.
+--------------------------+
| PublisherName            |
+--------------------------+
| Farrar Straus and Giroux |
| McPherson and Co.        |
| Simon and Schuster       |
| Thames and Hudson        |
+--------------------------+
4 rows in set (0.00 sec)

My code that I used is:

SELECT PUBLISHER_NAME
FROM PUBLISHER
WHERE PUBLISHER_NAME LIKE '%AND%';

However, my results pulls in an extra publisher: Random House due to the and in random.

Can someone point me in the right direct on what I am doing wrong?

Thanks


Solution

  • Try adding spaces between the text and the wildcard.

    SELECT PUBLISHER_NAME
    FROM PUBLISHER
    WHERE PUBLISHER_NAME LIKE '% AND %';