Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Subquery syntax
Message
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Environment versions
SQL Server:
SQL Server 2014
Application:
Web
Miscellaneous
Thread ID:
01615658
Message ID:
01615673
Views:
29
>>>>>>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.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform