Database Reference
In-Depth Information
LIKE
When you are searching for a string using the equals sign (=), SQL only searches for the
exact string. If you need to search for a string that began with Home , you need to use the
LIKE operator and pattern matching. To test this, we will add another row to our webpage
table which will point to a webpage that contains happy memories of where we grew up.
Add the row with the following query:
INSERT
INTO
webpage (Title, Content)
VALUES
(“Home is where the Heart is”,
“This page contains happy memories from my childhood”)
Select everything from the webpage table after running the query above just to check
that the new row has been added. You should now see several rows that have a Title column
that begin with the word Home . We will now try and retrieve all of those columns.
If you have programmed before, the temptation is to try the following query:
SELECT *
FROM
webpage
WHERE
Title = “Home*”
Figure 6.7 shows that when you run this query it doesn't produce what you would expect.
All that is given is the error message that the query produced no results.
To get that query working the way that we want, we need to use the LIKE operator in the
condition as follows:
SELECT *
FROM
webpage
WHERE
Title LIKE “Home%”
Figure 6.8 shows the results of running this query.
Figure 6.7 Equals will not work with fuzzy matching.
Search WWH ::




Custom Search