S
S
Steve2021-06-07 14:40:07
PostgreSQL
Steve, 2021-06-07 14:40:07

How to make a cleaner pgsql query without joins?

Good day!

select cons."Custom".*,
       array_agg(cons."PTarget"."Name" || ': ' || cons."SLine"."Quantity") as Prices
FROM cons."Custom"
       JOIN cons."Subscr" on cons."Subscr"."Custom" = cons."Custom"."Id"
       JOIN cons."SLine" on cons."Subscr"."Id" = cons."SLine"."Subscr"
       JOIN cons."Price" on cons."SLine"."PriceId" = cons."Price"."Id"
       JOIN cons."PTarget" on cons."PTarget"."Id" = cons."Price"."TargetId"
WHERE cons."Subscr"."Status" in ('New')
GROUP BY cons."Custom"."Id";


This query returns a list of groups with different joins, a bunch of joins to get to:
console."PTarget"."Name" and console."SLine"."Quantity"

Help me find a clean way to query this information about creating objects.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question