ایس ل سلیکٹ ڈسٹینکٹ عبارت

This chapter explains the SELECT DISTINCT statement.

ایس ل سلیکٹ ڈسٹینکٹ عبارت

In a table, there may be duplicate values. This is not a problem, but sometimes you may want to list only different (distinct) values.

The keyword DISTINCT is used to return unique values.

Syntax:

SELECT DISTINCT ColumnName FROM TableName

Use DISTINCT Keyword

If we want to select all values from the 'Company' column, we need to use the SELECT statement:

SELECT Company FROM Orders

"Orders" Table:

Company OrderNumber
IBM 3532
W3School 2356
Apple 4698
W3School 6953

Result:

Company
IBM
W3School
Apple
W3School

Please note that CodeW3C.com is listed twice in the result set.

To select only unique values from the 'Company' column, we need to use the SELECT DISTINCT statement:

SELECT DISTINCT Company FROM Orders

Result:

Company
IBM
W3School
Apple

Now, 'W3School' is listed only once in the result set.