SQL Tutorial: SQL SELECT DISTINCT Instance Tutorial

Source: Internet
Author: User
Tags sql tutorial one table

SQL Tutorial: SQL SELECT DISTINCT Instance 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.

SQL SELECT DISTINCT syntax.

SELECT DISTINCT column_name (s) from
table_name
Let's take a look at an example of a distinct record.
 
   
   
_id lastname firstname address city
1 Hansen ola timoteivn S Andnes
2 svendson Tove borgvn Sandnes
3 Pettersen Kari storgt 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 results are as follows. 
 
     
     
city
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.