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:
01615674
Vues:
32
>>>>>>>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.
>>>>
>>>>How do I modify your SQL Select so that if the value in T2.date_fld is equal to the current date, do not include in the resulting query?
>>>
>>>That's what the query is doing - if we have corresponding rows in the Table 2 with today's date, then we would not get these rows from the Table1 in the final result.
>>
>>Does not seem to work as I am testing. I will double check.
>
>Can you formulate again in plain English what are you trying to achieve and post your actual query?
>
>The query I posted will select all rows from Table1 that don't have corresponding rows in Table2 with today's date and particular value in the second column.

I want to include the rows from Table1 only if there is no corresponding row in Table2 (matching the id_field) that the value in field date_fld is current date. That is, if the row already added to the Table2 - today/current day - do not include it.
"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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform