I am using SQLite and I have a problem with making correct query request in following scenario:
I have four tables, let's call them t.a
, t.b
, t.c
, t.d
t.c
is in multiple to one relation with t.d
, so t.c
has column called parent_id_d
t.a
and t.c
are in multiple to multiple relation with each other so I created junction table called t.b
to link them to each other.
Now I want to make query request that returns joined rows from t.a
and t.d
where each row should have distinct entries in id_a
column from table t.a
and id_d
column from table t.d
(or parent_id
column from t.c
, its the same), generally something like DISTINCT id_a, id_d
but I want all rows from that table returned so I probably should use GROUP BY
with MIN
or MAX
as stated in this answer DISTINCT clause in SQLite But I can't get it working