To return distinct (unique) value of a particular column from a database table, we use
SELECT DISTINCT LastName FROM PersonalDetails
Above query will list records with unique LastName value from the PersonalDetails table.
In above case, the all 3 records have LastName as “Narayan”, only one unique value so only “Narayan” is listed as the result of the 2nd query.
If we keep more than only column with the DISTINCT keywords, uniqueness is determined with the combined value of all those columns.
SELECT DISTINCT LastName, FirstName FROM PersonalDetails
In above query, all three records will be given as result because the combined value of LastName and FirstName are unique.
Views: 5220 | Post Order: 45