Using the percent (%) wildcard 

There a few ways you can use the % wildcard, which represents zero or more characters. You can use it to find a value at the beginning, end, or middle of a string. For example, the following query will find all player IDs that start with the letter a

USE lahmansbaseballdb;
SELECT playerid, g_all, g_batting, g_defense
FROM appearances
WHERE playerid LIKE 'a%';

The previous query will return the rows shown in the following screenshot: 

If you move the % sign in front of the letter a, you are filtering on anything that ends in a. In this case, it will find no rows since playerid always ends in a number:

USE lahmansbaseballdb;
SELECT playerid, g_all, g_batting, g_defense
FROM appearances
WHERE playerid LIKE '%a';

The previous query will return no rows, as shown in the following screenshot:  

If you add a % sign to the end as well, then you will be filtering on any rows that have the letter a somewhere in the playerid value, as shown in the following query: 

USE lahmansbaseballdb;
SELECT playerid, g_all, g_batting, g_defense
FROM appearances
WHERE playerid LIKE '%a%';

The results of the previous query will provide the rows shown in the following screenshot: 

Avoid using wildcards at the beginning of a string, such as '%a' or '%a%'. Wildcards at the beginning of a string slows down the query processing. 

You can also place multiple characters before, after, or in-between percent wildcard. 

This query will return rows where playerid starts with the letters wr

USE lahmansbaseballdb;
SELECT playerid, g_all, g_batting, g_defense
FROM appearances
WHERE playerid LIKE 'wr%';

This query will return rows where playerid contains the letters ds

USE lahmansbaseballdb;
SELECT playerid, g_all, g_batting, g_defense
FROM appearances
WHERE playerid LIKE '%ds%';

To summarize, you can use the % wildcard to search for strings at the beginning, middle, or end of strings. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.195.97