0

I have the code presented below provided to me by one of the members but I do not understand how it acts:

select pdam.*, pr.*
from "DAMPay" as pdam left join lateral
     (select min(pr."AsigStart") as startt
      from "PolsRisc" as pr
      where pdam."PRID" = pr."Index"
     ) pr
     on true;

The code extracts the min of start from another table. I wanna add an aditional condition like:

where pdam."PAYDate" between '2020-06-01' and '2020-06-30'

I cannot insert the condition without an error. Also, I need only to see min(pr."AsigStart") from the pr table not all columns (pr.*). Thanks

1
  • What did you try, and which error did you get? Commented Jul 20, 2020 at 9:44

1 Answer 1

1

I want to add an aditional condition like:

You would typically add a where clause to your existing query:

select pdam.*, pr.*
from "DAMPay" as pdam 
left join lateral (
    select min(pr."AsigStart") as startt
    from "PolsRisc" as pr
    where pdam."PRID" = pr."Index"
) pr on true
where pdam."PAYDate" between '2020-06-01' and '2020-06-30'

Also, I need only to see min(pr."AsigStart") from the pr table not all columns (pr.*)

That's what the query does already. In the outer query, pr refers to the subquery (not to table PolsRisc). The subquery returns a single column, called startt, so that's pr.* is actually equivalent to pr.startt.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the query @GMB. Now it works but it seems the returned value min(start) is not correct. But your explination is fine. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.