SQL Tutorial: SQL SELECT DISTINCT instance tutorial

Source: Internet
Author: User
Tags sql tutorial

SQL Tutorial: SQL SELECT DISTINCT instance tutorial

This chapter explains how to select discrete speech.


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

Can be used to return only unique (different) values.

SQL SELECT DISTINCT syntax.

SELECT DISTINCT column_name(s)FROM table_name
Let's take a look at an instance with no repeated records in distinct.
 
 
_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger

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

We use the following SELECT statement:

SELECT DISTINCT City FROM Persons
 
The result is as follows.
  
  
City
Sandnes
Stavanger

Related Article

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.