About 50 results
Open links in new tab
  1. 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 functions.

  2. sql - DISTINCT for only one column - Stack Overflow

    Feb 19, 2017 · Then at the end you put the distinct column to filter and you only group it with that last distinct column. This will bring you the maximum ID with the correspondent data, you can use min or …

  3. sql - COUNT DISTINCT with CONDITIONS - Stack Overflow

    Dec 27, 2012 · tag | entryID ----+--------- foo | 0 foo | 0 bar | 3 If I want to count the number of distinct tags as "tag count" and count the number of distinct tags with entry id > 0 as "positive tag count" in the …

  4. sql - How to use DISTINCT and ORDER BY in same SELECT statement ...

    283 The problem is that the columns used in the ORDER BY aren't specified in the DISTINCT. To do this, you need to use an aggregate function to sort on, and use a GROUP BY to make the DISTINCT …

  5. sql - Using DISTINCT and TOP in the same query - Stack Overflow

    I want to use DISTINCT and TOP in the same query. I tried SELECT DISTINCT TOP 10 * FROM TableA but I still have a duplicate personID, so I tought to do: SELECT DISTINCT (personID) TOP 10 * …

  6. Using DISTINCT along with GROUP BY in SQL Server

    Is there any purpose for using both DISTINCT and GROUP BY in SQL? Below is a sample code SELECT DISTINCT Actors FROM MovieDetails GROUP BY Actors Does anyone know of any …

  7. Get unique values using STRING_AGG in SQL Server

    May 29, 2018 · Any simple example on how to use the STUFF and FOR XML with DISTINCT in my dataset? I can't avoid STRING_SPLIT as unfortunately the raw data is stored as delimited values as …

  8. sql - Should I use distinct in my queries - Stack Overflow

    Nov 11, 2015 · 7 In your example distinct and group by do the same thing. I think your colleagues means that your query should not return duplicates in the first instance and that you should be able …

  9. sql - Which is better: Distinct or Group By - Stack Overflow

    Feb 14, 2017 · I would add that adding distinct willy nilly to remove duplicate rows can be bad idea especially if it's use disguises a cross join or missing items in a where clause. Distinct would be my …

  10. MySQL: Select DISTINCT / UNIQUE, but return all columns?

    May 25, 2011 · You have selected the distinct column in the subquery but the where clause gets all those columns with that value. So the query is as good as writing 'select * from table' unless 'field' …