Actually,
If EXISTS (SELECT * FROM ProductShipped WHERE customerId = 10)
is in general more efficient.
The EXISTS predicate returns TRUE when the subquery given as its argument has any rows in it at all. The SELECT * allows the optimizer to select which column to use to satisfy the query, rather than directing it to use a specific one.
If your ProductShipped table has an index on the customerID column, then the optimizer can determine that the subquery has rows in it from the index, without having to actually SELECT a column from the table itself, which you force it to do by specifying the column in the SELECT clause.
The TOP 1 clause is very much worse, as that requires that the subquery fully generate all its rows before the result is limited by the TOP expression.
(Note that SELECT * in the EXISTS predicate subquery is an exception to the "rule" that says you really shouldn't use SELECT * in your queries, but rather always explicitly specify the columns you want selected)
Jeff Mason
[email protected]