sql - Bad value returned using EXISTS -
i trying return minimum fiscalyear
grouping on productid
using subquery , exists
operator. whatever reason, getting arbitrary value set of fiscal years. subquery returns minimum fiscalyear
outer query won't pick update
. ideas?
update#temp set sales_year = sa.fiscalyear sales sa join products p on p.id = sa.productid join #temp t on p.id = t.productid exists ( select min(sa.fiscalyear), sa.productid sales sa join products p on p.id = sa.productid join #temp t on p.id = t.productid group sa.productid )
you don't need join's outside exists. in addition, assume using sql server.
actually, don't think want exists
@ all. use =
this:
update t set sales_year = sa.fiscalyear #temp t t.product_id = (select top 1 sa.productid sales sa join products p on p.id = sa.productid order sa.fiscalyear )
Comments
Post a Comment