Here’s what the simple SQL would look like: SELECT DISTINCT employee_location from employee; Running this query will return the following results: employee_location New York India Russia Canada So, you can see that the duplicate values for "Russia" and "Canada" are not returned in the ...
Distinct SQL Example This sample illustrates use of DISTINCT keyword. The query returns all names from the field "FirstName" excluding duplicates. select distinct e1."FirstName" from "employee" e1 Download Absolute Database | Learn more
Use the DISTINCT keyword before the column names in an SQL statement to prevent duplicate rows from being selected. Examples The following example lists only the unique divisions that exist in the Q.ORG table: This query: SELECT DISTINCT DIVISION FROM Q.ORG Produces this report: DIVISION --- ...
You often find duplicate values in a field in a SQL Server database table. Duplicate records don’t necessarily mean there is anything wrong with the data. It’s not uncommon to have a table with customer addresses with multiple customers in the same city, state, and maybe even the same ...
SQL Distinct SQL Example: Unique List of Address Types It's not uncommon to have a customer's billing and shipping addresses be different. If we want to see our distinct address types, query the SalesLT.CustomerAddress table with a SELECT DISTINCT on AddressType. ...
Example: SELECT -- select all countries from the Customers tableSELECTcountryFROMCustomers; This SQL command will return all country entries, including duplicates, from theCustomerstable. To learn more, visitSQL SELECT. Write an SQL query to filter out all the duplicate entries. ...
DISTINCT column_name – This counts the number of distinct, non-null values in the specified column. Example 1: Count All Rows The most simplistic usage of the COUNT() function is to count all the rows in a given table. Take the following query for example that demonstrates how to use ...
The query example: SELECT DISTINCT FirstName, FirstName + ' ' + LastName AS FullName FROM Person.Person ORDER BY LastName Causes the following error: ORDER BY items must appear in the select list if SELECT DISTINCT is specified. Because of this you must keep in mind, when using ORDER ...
SELECT DISTINCT product_id, quantity FROM ORDER_ITEMS ORDER BY product_id;Code language: SQL (Structured Query Language) (sql) The following illustrates the result: In this example, both values the product_id and quantity columns are used for evaluating the uniqueness of the rows in the result...
For example, let’s say we have a table of students, and we want to get a count of the number of unique students in the table. We can use the following SQL query: SELECT COUNT(DISTINCT student_id) FROM students; This query will return the number 10, which is the number of unique ...