QuestDB
Get Started
  • Docker
  • Binaries
  • Homebrew
Resources
  • Customers
  • Enterprise
  • Blog
  • Tutorials
  • Videos
Community
  • GitHub
  • Slack
  • Stack Overflow
  • Twitter
Documentation
Get QuestDB
QuestDB
  • Get Started
    • Docker
    • Binaries
    • Homebrew
  • Resources
    • Customers
    • Enterprise
    • Blog
    • Tutorials
    • Videos
  • Community
    • GitHub
    • Slack
    • Stack Overflow
    • Twitter
  • Documentation
  • Introduction
  • Concepts
    • Storage model
    • Designated timestamp
    • SQL extensions
    • Partitions
    • Symbol
    • Indexes
    • Root directory
  • Get Started
    • Docker
    • Binaries
    • Homebrew
    • Create my first database
  • Develop
    • Connect
    • Insert data
    • Query data
    • Authenticate
  • Third-party Tools
    • Grafana
    • Kafka Connect
    • Telegraf
  • Operations
    • Capacity planning
    • Deployment
    • Data retention
    • Health monitoring
  • Reference
    • API
      • REST
      • Postgres
      • InfluxDB
      • Java (embedded)
    • Command-line options
    • Configuration
    • Functions
      • Aggregation
      • Conditional
      • Date and time
      • Meta
      • Numeric
      • Random value generator
      • Row generator
      • Text
      • Timestamp generator
      • Timestamp
    • SQL
      • SQL execution order
      • Data types
      • ALTER TABLE
        • ADD INDEX
        • ADD COLUMN
        • RENAME COLUMN
        • DROP COLUMN
        • DROP PARTITION
      • BACKUP
      • CASE
      • CAST
      • COPY
      • CREATE TABLE
      • DISTINCT
      • EXCEPT & INTERSECT
      • FILL
      • DROP TABLE
      • GROUP BY
      • INSERT
      • JOIN
      • LATEST BY
      • LIMIT
      • ORDER BY
      • RENAME TABLE
      • SAMPLE BY
      • SELECT
      • SHOW
      • TRUNCATE TABLE
      • UNION
      • WHERE
      • WITH
    • Web Console

DISTINCT keyword

SELECT DISTINCT is used to return only distinct (i.e different) values from a column as part of a SELECT statement.

Syntax#

Flow chart showing the syntax of the DISTINCT keyword

Examples#

The following query will return a list of all unique ratings in the table.

Simple query
SELECT DISTINCT movieId
FROM ratings;

SELECT DISTINCT can be used in conjunction with more advanced queries and filters.

With aggregate
SELECT DISTINCT movieId, count()
FROM ratings;
With filter
SELECT DISTINCT movieId, count()
FROM ratings
WHERE score > 3;
Previous
« CREATE TABLE keyword
Next
EXCEPT & INTERSECT keywords »
  • Syntax
  • Examples
QuestDB logo

QuestDB is the fastest open source time series database

GitHub logoStar us on GitHub
  • QuestDB
  • Enterprise
  • Customers
  • Careers
  • Community
  • GitHub
  • Slack
  • Stack Overflow
  • Twitter
  • More
  • Documentation
  • Tutorials
  • Blog
  • Videos
  • Roadmap

Copyright © 2021 QuestDB