sql - How to change subQuery to Co-related Subquery? -
query
select firstname, lastname adventureworks.person.contact inner join [adventureworks].[humanresources].[employee] b on a.contactid = b.contactid b.employeeid in ( select salespersonid adventureworks.sales.salesperson c c.bonus = 5000)
how change above subquery co-related subquery?
i think you're looking for. move query from
section , use join
filter results based on same conditions had in where
clause, except time reference result set (rs) returned subquery.
select firstname, lastname adventureworks.person.contact inner join [adventureworks].[humanresources].[employee] b on a.contactid = b.contactid inner join (select salespersonid adventureworks.sales.salesperson c c.bonus = 5000) rs on b.empoyeeid = rs.salespersonid
although functional, done easier , faster using join
salesperson table directly.
select firstname, lastname adventureworks.person.contact inner join [adventureworks].[humanresources].[employee] b on a.contactid = b.contactid inner join salespersonid c on b.empoyeeid = c.salespersonid , c.bonus = 5000
Comments
Post a Comment