How to Use Exists Clause

  • I am using the EXISTS Clause as

    1. IF Exists(Select Specialty from Doctors)

    Select 'Yes'

    Can anybody tell me that is the following query is better or faster than the st query?

    IF Exists(select * from Doctors)

    select 'YES'

    Whether to user Exist (select * from tablename ......) or Exist (select FieldName from tablename.......)

    Thanx for the help!!!! 🙂

    Thanks.

    Gunjan.

  • Performance will not make a difference, but they can return different results.

    If the field you reference when not using * returns all NULL values, even if there are rows in the table, the EXISTS will be false.

  • Thanks.

    But it will be good if my next statements will be based upon that field.

    Then it will improve the perfomance...

    right??

    Thanks.

    Gunjan.

  • I checked..

    Even if the field is NULL it returns the "True" in EXISTS statement...

    Thanks.

    Gunjan.

  • I am not sure what you meant by this:

    [font="Courier New"]But it will be good if my next statements will be based upon that field.

    Then it will improve the perfomance...

    right?? [/font]

    but the EXISTS performance will be the same either way.

    You can, of course, just look at the execution plans - this is pretty easy to test.

  • If you know that you are looking for single field from the table...the definately you should go for if Exists(Select Specialty from Doctors)

  • Khelan I think you didn't got the question....

    Its about performace.......

    which is better one??

    Thanks.

    Gunjan.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply