I understand that I may need to do grouping to accomplish this, but I can\'t quite get it. Postgresql 8.1
I am needing to limit my result set to Origination > 2017-01-01
Here is how you did it - alias in the column name
select
-- etc etc
(select innerDLI.datetime_created from distribution_line_items innerDLI where innerDLI.item_number = distribution_line_items.item_number order by innerDLI.datetime_created asc limit 1) as Origination,
-- etc etc
from distribution_stop_information
-- etc etc
Here is how you can put it in the where, alias in the join
select
-- etc etc
Origination.datetime_created
-- etc etc
from distribution_stop_information
left join distribution_line_items AS Origination ON Origination.item_number = distribution_line_items.item_number
where Origination.datetime_created > to_date(?, 'YYYY-MM-DD') - interval '180 days'
-- etc etc
There is nothing about this that is better than the solution you posted (the sql optimizer should result in the same plan) but it is "using an alias in the where clause"