| <?xml version="1.0" encoding="UTF-8"?> |
| <!-- |
| Licensed to the Apache Software Foundation (ASF) under one |
| or more contributor license agreements. See the NOTICE file |
| distributed with this work for additional information |
| regarding copyright ownership. The ASF licenses this file |
| to you under the Apache License, Version 2.0 (the |
| "License"); you may not use this file except in compliance |
| with the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, |
| software distributed under the License is distributed on an |
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| KIND, either express or implied. See the License for the |
| specific language governing permissions and limitations |
| under the License. |
| --> |
| <!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd"> |
| <concept id="distinct"> |
| |
| <title>DISTINCT Operator</title> |
| |
| <prolog> |
| <metadata> |
| <data name="Category" value="Impala"/> |
| <data name="Category" value="SQL"/> |
| <data name="Category" value="Querying"/> |
| <data name="Category" value="Aggregate Functions"/> |
| <data name="Category" value="Developers"/> |
| <data name="Category" value="Data Analysts"/> |
| </metadata> |
| </prolog> |
| |
| <conbody> |
| |
| <p> |
| The <codeph>DISTINCT</codeph> operator in a <codeph>SELECT</codeph> statement filters the |
| result set to remove duplicates. |
| </p> |
| |
| <codeblock>-- Returns the unique values from one column. |
| -- NULL is included in the set of values if any rows have a NULL in this column. |
| SELECT DISTINCT c_birth_country FROM customer; |
| |
| -- Returns the unique combinations of values from multiple columns. |
| SELECT DISTINCT c_salutation, c_last_name FROM customer;</codeblock> |
| |
| <p> |
| You can use <codeph>DISTINCT</codeph> in combination with an aggregation function, |
| typically <codeph>COUNT()</codeph>, to find how many different values a column contains. |
| </p> |
| |
| <codeblock>-- Counts the unique values from one column. |
| -- NULL is not included as a distinct value in the count. |
| SELECT COUNT(DISTINCT c_birth_country) FROM customer; |
| |
| -- Counts the unique combinations of values from multiple columns. |
| SELECT COUNT(DISTINCT c_salutation, c_last_name) FROM customer;</codeblock> |
| |
| <p conref="../shared/impala_common.xml#common/zero_length_strings"/> |
| |
| <note> |
| <p> |
| In contrast with some database systems that always return <codeph>DISTINCT</codeph> |
| values in sorted order, Impala does not do any ordering of <codeph>DISTINCT</codeph> |
| values. Always include an <codeph>ORDER BY</codeph> clause if you need the values in |
| alphabetical or numeric sorted order. |
| </p> |
| </note> |
| |
| </conbody> |
| |
| </concept> |