I have a slow SQL Server query:
SELECT Style
FROM Storage
WHERE Style NOT IN (SELECT ValidStyle FROM ValidStyles)
This syntax causes SELECT ValidStyle FROM ValidStyles to execute once for each row of the parent query. How can I rewrite this to run the subquery one time only?
SELECT Style
FROM Storage s
WHERE NOT EXISTS(SELECT * FROM ValidStyles vs WHERE vs.ValidStyle=s.Style)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With