Contents
When to select distinct and one another column of the ID?
Where id is unique for each row, department is the column which should be distinct, and tbl is the table name. If you want to only perform this check on non-NULL values (so all NULL values for department are still returned), this can be tweaked to:
When to use the SELECT DISTINCT statement in SQL?
The SELECT DISTINCT statement is used to return only distinct (different) values. Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different (distinct) values. SELECT DISTINCT column1, column2,
How to calculate the number of distinct values in a list?
To get a count of distinct values in a list, use the following formula: =SUM (1/COUNTIF (range, range)) Remember, it’s an array formula, and therefore you should press the Ctrl + Shift + Enter shortcut instead of the usual Enter keystroke.
Is there a way to select distinct departments?
However, you can’t simply get distinct departments if some departments have multiple Id’s – you need to figure out which of the multiple Id’s you want (max? min? something else?).
How to select distinct and Max in same query?
I think Itay Moav-Malimovka ‘s solution is just perfect, however if you really want to have two columns you could use …. Cheers! Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question. Provide details and share your research! But avoid … Asking for help, clarification, or responding to other answers.
Why is the shape field not included in distinct statement?
So the results of a complex distinct statement on two different (but similar) tables is unioned. The problem is that the SQL Geometry type (the SHAPE field) cannot be included in a distinct statement because it is not a comparable type. I’m okay with removing the SHAPE field from both of the subqueries that take part in the union.