SQL SELECT DISTINCT Syntax and usage tutorial

Source: Internet
Author: User
Tags one table

SQL SELECT DISTINCT Syntax and usage tutorial

This chapter will explain the choice of discrete speakers.

Select a different declaration in SQL
In one table, some columns may contain duplicate values. This is not a problem, however, sometimes you will want to list only the different (different) values on the table.

Unique keywords can be used to return only unique (different) values.

Choose a different SQL syntax

SELECT DISTINCT column_name (s) from
table_name
 
 

Choose a different role model
In the person table:

Address City
p_id LastName FirstName
1 Hansen Ola TIMOTEIVN 10 Sandnes
2 Svendson Tove BORGVN 23 Sandnes
3 Pettersen Kari STORGT 20 Stavanger

Now, we want to select only the different values from the column named "City" from the above table.

We use the following SELECT statement:

 select DISTINCT City from Persons 
 

The result-set would look like this :

 Note: Reprint please indicate from www.111cn.net/database/database.html 
ci Ty
sandnes
Stavanger

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.