SELECT DISTINCT in a field that does not appear in the recordset?

I want to do SELECT DISTINCT guid, ..., but I do not want to guidappear in the recordset. How to do it?

+3
source share
4 answers

Wrap it in a subquery?

select my, interesting, columns
from (
    select distinct GUID, ...
    from ...
)
+2
source
SELECT a.Field2
     , a.Field3
  FROM (SELECT DISTINCT a.guid
                      , a.Field2
                      , a.Field3
                   FROM table1 a)  a
+5
source

You can also do

SELECT x, y FROM tbl GROUP BY guid, x, y

The disadvantage here is that you need to duplicate the list of columns in the sentence GROUP BY, which is annoying, but other answers also do.

+3
source

first select individual values ​​in the temp table.

Then select only the desired values.

0
source

Source: https://habr.com/ru/post/1745294/


All Articles