Example 1 Deletes any discount from stores that have no sales, or that have discounts greater than 10:
create view store_with_nosales(stor_id) as select stores.stor_id from stores left join sales on stores.stor_id = sales.stor_id where sales.stor_id IS NULL go delete from discounts where (stor_id in (select * from store_with_nosales) or discount > 10.0) go
Example 2 Returns an error because there is more than one column in the join between stores and sales:
create view store_with_nosales(stor_id) as select stores.stor_id from stores left join sales on stores.stor_id = sales.stor_id where (stor_id in (select * from stores left join sales on stores.stor_id = sales.stor_id where sales.stor_id IS NULL) or discount > 10.0) go delete from discounts where (stor_id in (select * from store_with_nosales) or discount > 10.0) go
Msg 299, Level 16, State 1: Line 1: The symbol '*' can only be used for a subquery select list when the subquery is introduced with EXISTS or NOT EXISTS or the subquery references a single table and column.