Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Subquery syntax
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Versions des environnements
SQL Server:
SQL Server 2014
Application:
Web
Divers
Thread ID:
01615658
Message ID:
01615669
Vues:
20
>>>If you're looking into a query from table1 where you don't have rows with today's day and field2 = 'ABC' in the second table, then use NOT EXISTS subquery, e.g.
>>>
>>>select * from Table1 T1 where not exists (select 1 from Table2 T2 where T2.id_field = T1.id_field
>>> and CAST(T2.date_fld  as date) = cast(CURRENT_TIMESTAMP as date)
>>>and T2.field2 = 'ABC')
>>
>>Without testing, intuitively I think that this one would be faster. Thank you.
>
>If you only need rows from Table1 which satisfy the condition of not having corresponding rows in table2 with today's date and particular value of the field2, then this is the query you should use. It is fast and the other one has different meaning.

Yes, I only need rows from Table1 since if there is a row in Table2 (matching the WHERE) I want to exclude this from selecting. And I just tried it on a sample database and it executes fairly fast.
Again, thank you.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform