Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära SQL Distinct | Database & Introduction to Syntax
SQL Tutorial for Beginners

book
SQL Distinct

Distinct is a keyword used with SELECT to return only unique values. Usually, you want to get all unique values, but there are duplicate values stored in the tables.

Check the difference: in our table, there are 18 records at all, and each record has a singer. You'll retrieve the 18 singers with the next query:

SELECT singer
FROM songs
12
SELECT singer FROM songs
copy

But some singers, for example, AC/DC, occur multiple times. To retrieve the unique singers, use the DISTINCT keyword before the singer column:

SELECT DISTINCT singer
FROM songs
12
SELECT DISTINCT singer FROM songs
copy

Now there are no repeated values, so you can see that the total number of unique singers is 10.

Uppgift

Swipe to start coding

Find all unique title values in songs.

Lösning

SELECT DISTINCT title FROM songs

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 4

Query ResultQuery Result
No query executed yet...

Fråga AI

expand
ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

some-alt