DISTINCT in SQL SELECT

DISTINCT is used in the SELECT statement to find out the different items that can be found within a column. Any repeated items are not taken into account. The syntax for this is:

SELECT DISTINCT column FROM table

In this way we can find out, for example, which color sets in which we have a stake in our monopoly_prop table.

idstreet_namecolor
1Connecticut Avelight blue
2Oriental Avelight blue
3Kentucky Avered

We make the following query:

SELECT DISTINCT color FROM monopoly_prop

The results of this statement will be very simple: a column listing the different colors and named for the column queried:

color
Light Blue
Red

Adding an additional column to the SELECT DISTINCT query will mean both columns will be taken into account to determine the uniqueness of the row.

SELECT DISTINCT street_name, color FROM monopoly_prop

This will yield all the rows, but only the info in the columns requested. What you can NOT do is something like this: "SELECT * DISTINCT color FROM monopoly_prop" to get the additional column data.

< DELETE Statement SQL | DROP Statement SQL >


Send notes in disappearing ink!

Interesting Pages