1. DISTINCT Statement (DISTINCT) SQL SELECT DISTINCT statementIn the table, duplicate values may be included. That's not a problem, but sometimes you might want to just list differentvalues (distinct). Keyword DISTINCT is used to
are posted below, for the time being I do not know why this is happening.
For the first query, select the field after the order by, and the result screenshot is as follows:
The second query, the field following the order by is not followed by the Select, and the result screenshot is as follows:
The results of two queries are completely different, and using the disti
In daily work, sometimes some activities may need to win the prize or select some spot check lists ,?The order by newid () method is often used for random number selection ,?However, it is possible that distinct should be used together. At this time, such as distinct and order by newid ()?When used at the same time, an error message is displayed.
If
statement to query all data with no duplicate names, you must use distinct to remove redundant duplicate records.
Select distinct name from tableThe result is:
NameABC
It seems that the effect has been achieved, but what I want to get is the id value? Modify the query statement:
Select
The DISTINCT technique and usage in the select statement are occasionally displayed in a forum about the DISTINCT technique and usage. it is written by a moderator. I think it may be helpful to some people. so it is Reprinted. convenience
Below is the reprinted content
Unique query for a single table: distinctUnique query for multiple tables: groupWhen using
no duplicate names, you must use distinct to remove redundant duplicate records.
Select distinct name from tableThe result is:
NameABC
It seems that the effect has been achieved, but what I want to get is the ID value? Modify the query statement:
Select distinct nam
, must have the same ID and test1 will be excluded, this is not possible, the ID is automatically increased ...Let's change the query statement:Select ID, distinct test1 from testUnfortunately, in addition to the error message you get nothing, distinct must be placed at the beginning. Is it difficult to put distinct in a where condition? Can, still error ....The
a test, success.Finally, but then, you have to ask customers to upgrade.Suddenly the spirit flashes, and since you can use the Group_concat function, can the other functions be OK?Hurriedly with the Count function a try, success, cost so much effort, originally so simple.Now release the full statement:SELECT *, COUNT (distinct name) from the table group by nameResults:ID Name count (distinct name)1 a 12 B
Tags: attr date database red Phone tail archive description Callselect/distinct operator Application Scenario : O (∩_∩) o ... Query for Bai. Description : Unlike the SELECT function in the SQL command, the SELECT and the clauses in the query expression are placed at the end of the expression and the variables in the sentence are returned;
How to use SQL select distinct, selectdistinct
Duplicate values may exist in the table. This is not a problem. However, sometimes you may want to list only different values. The keyword distinct is used to return a unique value.
Table:
Example 1
Copy codeThe Code is as follows:Select distinct name from
The resul
Select/Distinct Operator
Description: Similar to the select statement in SQL commands, the select statement and the clause in the query expression are placed at the end of the expression, and the variables in the clause, that is, the results are returned. delay.
Select/
Tags: NiO except implementation note technology inter picture step Figure 1 If there are duplicate rows in the UNION, they will be removed, leaving only one 1. Introduction The except and INTERSECT operators allow you to compare the results of two or more SELECT statements and return distinct values. 2. Differences The except operator returns all distinct values
Bear11.9900RGAN01 raggedy Ann4.9900RYL01 King Doll9.4900RYL02 Queen Dool9.4900Retrieving all ColumnsSELECT *
from Products;Warning: Using wildcard charactersIn general, it is best not to use the * wildcard character unless you really need each column in the table. Although using wildcards can save you the hassle of not explicitly listing the required columns, retrieving the columns you don't need often reduces the performance of your search and applications.Tip: Retrieving unknown columns usin
ArticleDirectory
Syntax:
"Orders" table:
Result:
Result:
SQL select distinct statement
Duplicate values may exist in the table. This is not a problem. However, sometimes you may want to list only different values.
The keyword distinct is used to return a unique value. Syntax:
Select
Label:In the table, duplicate values may be included. That's not a problem, but sometimes you might want to just list different values (distinct). Keyword DISTINCT is used to return only different values.Grammar:SELECT DISTINCT column name from table nameUsing DISTINCT KeywordsIf you want to pick all the values from th
This chapter explains the SELECT DISTINCT statement.
SQL SELECT DISTINCT Statement
In a table, you might include duplicate values. This is not a problem, but sometimes you may want to list only the different values (distinct).
Keyword
Tags: any body different statement class BER select repeat ProblemSQL SELECT DISTINCT StatementIn the table, duplicate values may be included. That's not a problem, but sometimes you might want to just list different values (distinct). Keyword DISTINCT is used to return only
SELECT/DISTINCT operations include 9 forms, namely simple usage, anonymous type form, conditional form, specified type form, filter form, shaping type form, nested type form, local method invocation form, distinct form.1. Simple usage:This example returns a sequence that contains only the name of the customer contact person.var q =From C in DB. CustomersSelect C.
Label:The data table used in the following example
LastName
FirstName
Address
City
Year
Adams
John
Oxford Street
London
1970
Bush
George
Fifth Avenue
New York
1975
Carter
Thomas
Changan Street
Beijing
1980
Gates
Bill
Xuanwumen 10
Beijing
1985
SELECT
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.