on 2023 Oct 04 8:49 AM
Is it possible to select 2 columns distinctly in one single select statement?
In this example I have the problem that 'Michael' will be listed twice:
create or replace table employees (firstname varchar(100), lastname varchar(100), phone varchar(100)); insert into employees values ('Michael', 'Carthy', '01123456'), ('John', 'Carther', '01654321'), ('Raphael', 'Michael', '01654123'); select list (distinct firstname) || ',' || list (distinct lastname) from employees
One way to solve the problem is something like this (approach B):
select list(distinct f1) from (select firstname f1 from employees union select lastname f1 from employees) T1
But I want to avoid the second select statement, since the table employees enough big is.
Request clarification before answering.
DISTINCT removes duplicate rows from a result set but does not operate at a individual column level in a result set. The UNION is a reasonable solution based on the requirement.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
61 | |
8 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.