SELECT DISTINCT

The DISTINCT qualifier (and its synonym DISTINCTROW) allows you to weed out multiple entries when they contain the same data. For instance, suppose that you want a list of all authors in the table. If you select just the author column from a table containing multiple cd:s by the same author, you’ll normally see a long list with the same author names over and over. But by adding the DISTINCT keyword, you can show each author just once. So, let’s test that out by adding another row that repeats one of our existing authors.

Duplicating data:

INSERT INTO classics(author, title, category, year, isbn)
VALUES(‘Markku Aro’,’30 suosikkia’,’POP’,’1998′, ‘5051011157622’);

Now that Markku Aro appears twice in the table, we can compare the results of using SELECT with and without the DISTINCT qualifier.

show that the simple SELECT lists Aro twice, and the command with the DISTINCT qualifier shows him only once.

With and without the DISTINCT qualifier:
SELECT author FROM classics;
SELECT DISTINCT author FROM classics;

Leave a Reply

Your email address will not be published. Required fields are marked *