Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

How To Use Distinct In Sql in SQL

How To Use Distinct In Sql in SQL

How to Use DISTINCT in SQL

The DISTINCT keyword is used to return only unique (different) values from a column or a set of columns, eliminating duplicates in the result set.


Syntax:

SELECT DISTINCT column1, column2, ...FROM table_name;

Example 1: Distinct Values in One Column

Suppose you have a table employees with a department column, and you want to find all unique departments:

SELECT DISTINCT departmentFROM employees;

Example 2: Distinct Combinations of Multiple Columns

To get unique combinations of department and job_title:

SELECT DISTINCT department, job_titleFROM employees;

Notes:

  • DISTINCT applies to all selected columns together.

  • It removes duplicate rows from the result.

  • Useful when you want to count or list unique values.


If you want, I can show you how to use DISTINCT with aggregation or other clauses!

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql