
How to select unique records by SQL - Stack Overflow
DISTINCT works to select a distinct combination of all the columns you selected. In this case, the combination "item1,data1" and "item1,data2" are two completely different combinations of the …
How do I (or can I) SELECT DISTINCT on multiple columns?
Sep 10, 2008 · The problem with your query is that when using a GROUP BY clause (which you essentially do by using distinct) you can only use columns that you group by or aggregate …
sql - DISTINCT for only one column - Stack Overflow
Feb 19, 2017 · SELECT DISTINCT TOP 1 ID, Email, ProductName, ProductModel FROM Products ORDER BY ID DESC The TOP 1 will return only the first record, by ordering it by the …
sql server - SELECT DISTINCT on one column - Stack Overflow
1 FOO-23 Orange 3 FOO-24 Apple This query isn't getting me there. How can I SELECT DISTINCT on just one column?
sql server - SQL: How do I SELECT only the rows with a unique …
May 5, 2015 · SELECT DISTINCT [contract], activity FROM @T AS A WHERE (SELECT COUNT( DISTINCT activity ) FROM @T AS B WHERE B.[contract] = A.[contract]) = 1 returns: …
SQL to find the number of distinct values in a column
Apr 5, 2019 · SELECT COUNT(DISTINCT column_name) AS some_alias FROM table_name This will count only the distinct values for that column.
sql - Using DISTINCT and TOP in the same query - Stack Overflow
SELECT DISTINCT TOP 2 name FROM [ATTENDANCE] ; In the above query, name is the column_name and [ATTENDANCE] is the table_name. You can also use WHERE with this to …
MySQL: Select DISTINCT / UNIQUE, but return all columns?
May 25, 2011 · SELECT DISTINCT FIELD1, FIELD2, FIELD3 FROM TABLE1 works if the values of all three columns are unique in the table. If, for example, you have multiple identical values …
sql - Selecting COUNT (*) with DISTINCT - Stack Overflow
SELECT program_type AS [Type], Count(DISTINCT program_name) AS [Count], FROM cm_production WHERE push_number = @push_number GROUP BY program_type …
sql - DISTINCT clause with WHERE - Stack Overflow
How can I use the DISTINCT clause with WHERE? For example: SELECT * FROM table WHERE DISTINCT email; -- email is a column name I want to select all columns from a table with …