Hi,
I have a problem with double entries in a query that I cannot fix.
The table has one column "code". This is a varchar with special fixed formatting:
1-8: Code-ID
22-30: Host.
In many queries I always work with the Code-ID using the code
Code:
substr(code,1,8) as Code-ID
substr(code,22,8) as Host
Now I want to have a list of all Code-IDs unique. I get it with this:
Code:
Select distinct(substr(code,1,8)) from summary
For a dropdown Box, I now want to have a list with the following output:
Code:
| Code-ID | (Code-ID+" - "+Host) |
I hope it is understandable what I mean inside the brackets. A concat of the id and the host with " - " between.
That wouldn't also be that hard,
but - and now the point:
I really want the Code-Id to be unique, only one time in the result. Which host I then have in the column doesn't matter, any is good.
The column code has several entries for ONE Code-ID with different hosts.
This query mostly doesn't make sense, but in my case I need it :-)
I tried it with several Joins (left inner) but I always get double results...
This was one of my various tries:
Code:
With c(code) as
(
SELECT distinct(substr(code,1,8)) as code from summary
order by code
),d(code, host) as
(
SELECT distinct(substr(code,1,8)) as code, substr(code,22,8) as host from summary
)
Select distinct(c.code), d.host from c left join d on c.code = d.code
group by code, host
;
Thank you!