Home Forums SQL Server 2005 T-SQL (SS2K5) EXISTS Subqueries: SELECT 1 vs. SELECT * (Database Weekly 11.02.2008) RE: EXISTS Subqueries: SELECT 1 vs. SELECT * (Database Weekly 11.02.2008)

  • I am a little confused by this thread.

    Ignore my post if you meant the same as I write now:

    I am pretty sure that SQL Server does NOT make a difference between

    EXISTS(SELECT 1...

    or

    EXISTS(SELECT *...

    Reason is the following: SQL Server does not need to retrieve any column list for the SELECT clause to determine if a FROM clause in conjunction with a WHERE clause return any rows - it is just not relevant. And since SQL Server is smart enough, it (he? she?) simply ignores the SELECT clause.

    The select list of a subquery introduced by EXISTS almost always consists of an asterisk (*). There is no reason to list column names because you are simply testing for the existence of rows that meet the conditions specified in the subquery.

    http://technet.microsoft.com/en-us/library/ms189259.aspx

    Best Regards,

    Chris Büttner