I'm working now on SQL query for Polarion widget, where I want get items with unresolved comments. Unfortunately, I have a problem with joining three tables where one has optional empty/null. In Polarion is a few different tables to contain comments, most of them has a resolved status. I'm using WORKITEM, COMMENT, MODULECOMMENT tables, because sometimes workitem has comment here, sometimes in another table.
Difference is one: when workitem has "normal" comment, then there is always FK key in COMMENT table, but not each workitem has a FK MODULE key (table structure).
In default widget, I can use SQL query with a one big limit: I can't replace whole select and from, because there is a static line: SELECT WORKITEM.C_URI and FROM WORKITEM, so I can only add something (I tried DISTINCT ON, but how can you see, I can't replace that line)
Polarion has another problem too, each document has headings, texts etc. and each of this element is separate workitem with the same FK_URI_MODULE (and documents use MODULECOMMENT table).
I want remove duplicates from MODULECOMMENT (ignore situation where workitem.FK_URI_MODULE is empty/null, because it's normal state).
The best what I created, It's here (in this situation I replace is null to is not null, because It's return less items):
select workitem.c_uri, workitem.FK_URI_MODULE
from workitem
left join COMMENT on COMMENT.FK_URI_WORKITEM = WORKITEM.C_URI
left join MODULECOMMENT on MODULECOMMENT.FK_URI_MODULE = WORKITEM.FK_URI_MODULE
where true
and workitem.fk_uri_project = 231
and (comment.c_resolved is not null
or modulecomment.c_resolved is not null);
and my results:
c_uri | fk_uri_module
--------+---------------
7952 | 7940
7949 | 7940
7953 | 7940
7964 | 7940
124141 | 124138
609 |
1347 |
609 |
but I want get something like that:
c_uri | fk_uri_module
--------+---------------
7952 | 7940
124141 | 124138
609 |
1347 |
609 |