Use of DISTINCT in SELECT close
Ivan Smahin
ivan_smahin at paradigmasoft.com
Tue Dec 1 01:14:56 CST 2015
Hi Stan,
> On Nov 30, 2015, at 3:03 PM, Stanley Roche Busk <maxprog at mac.com> wrote:
>
>
> Ok, actually ‘a' is a string and ‘b' a record number. I try to get all the different versions of ‘a’. ‘a’ may or may not be different, ‘b’ is always different.
>
> SELECT (a), b FROM c GROUP BY a ??? I am not in front of my working dev. computer right now so I can’t try :-(
>
> Stan
>
>
François Van Lerberghe is absolutely right.
Actually, you want to group results by "a" column. It means - some single value (based on group of "b" values) for each distinct "a" value.
You should only decide what aggregation function to apply for each group.
Something like this one:
SELECT a, MIN(b) FROM c GROUP BY a;
Another example - if you want to get a list of "b" values (as single value) for each "a" group:
SELECT a, GROUP_CONCAT(b) FROM c GROUP BY a;
...
>> On Nov 30, 2015, at 1:38 PM, François Van Lerberghe <frvanlerberghe at gmail.com> wrote:
>>
>> Hello Stan,
>>
>> You must decide what you do for the b column when there is duplicates on column a : you take the first, the last, …
>>
>> If you decide to take the first value, your sql query could be this one : SELECT a, FIRST(b) FROM c GROUP BY a
>>
--
Best regards,
Ivan Smahin
Senior Software Engineer
Paradigma Software, Inc
Valentina - The Ultra-Fast Database
http://www.valentina-db.com
More information about the Valentina
mailing list