Learning how to use the DISTINCT clause 

DISTINCT is a keyword that, when added to a SELECT statement, will return only distinct (or different) values within a column. Sometimes, you may want to see what values are contained in a column, and getting the distinct values will help you see this. For example, if you want to see the distinct player IDs in the appearances table, you should execute the following query: 

USE lahmansbaseballdb;
SELECT DISTINCT playerid FROM appearances;

The following screenshot shows the results of the preceding query. Note that the rows returned are far fewer than in the previous section. This list only shows the distinct player IDs, and there are 19,429 of them:

You can also select multiple columns in DISTINCT. For instance, if you want to select distinct teams and players on those teams, you can execute the following query: 

USE lahmansbaseballdb;
SELECT DISTINCT teamid, playerid FROM appearances;

The previous query will give you the results shown in the following screenshot: 

The previous screenshot shows that you are getting distinct teams and players on those teams and that 45,825 rows have been returned. 

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

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