Use Sql Distinct to select unique rows of a table.
The "column_list" after the DISTINCT keyword determine the uniqueness of the rows. If you select only one column, the Sql will select unique entries of that column. If you select two columns, the Sql will select unique combination of those two columns.
Often the Sql Distinct is combined with the Sql Count, so instead of getting the list, it will show the total number of distinct rows.
Let's use the CONTACTS table again for illustration. The task is to list the values of State in that table.
To do this write this sql:
You get 3 rows in the result:
Let's experiment by adding Postcode to the column list.
Write the following Sql:
And the result has 4 rows:
Why the 'NSW' appears twice? It's because the program checks uniqueness row-wise,i.e. the combination of State and Postcode.
When you use DISTINCT keyword, make sure you dont include the Primary Key of the table (CPId in this case) in the column list, otherwise it will just list everything in that table. Because the Primary Key is unique for all rows.
Quick link. From here, you can learn the following:
The core of Sql, selecting data from table.
Conditionally selecting rows from table.
Pattern searching for conditions in Where or Having clause
Added to conditions to show results between two values.
It enables us to specify multiple values, either as a list or a subquery.
Sql And Or
Connecting two or more conditions in the Where or Having clause.
Counting number of rows.
Getting the sum of a field
This function will return the highest value.
This function will return the lowest value.
This function will return the average value.
Sql Order By
Sorting the output
Sql Group By
Grouping rows into sets.
To filter the result of aggregation
Return from Sql Distinct to Sql Commands
All of us have at least two or three things that excite us. We could talk about these subjects for hours. Good news!. Did you know that Site Built It! can turn this type of deep interest and enthusiasm into a revenue-generating business?
Review some of the Site Build It! case studies and you'll absolutely discover something that ignites more positive ideas into your mind.
SBI! Video Tour
Invest the most
Buy at AllPosters.com
Sydney Harbor Bridge, Sydney, Australia