Reputation: 111
I have two tables: TableA and TableB (as in the following picture):
The result should be as in the following figure:
What is the best way to get result (as in the table Result) using mssql query?
Thanks.
Upvotes: 0
Views: 73
Reputation: 1269953
If I understand correctly, you want the date/value pairs that don't exist.
Generate the list of all date/value pairs using a cross join
. Then filter out the ones you don't want:
select b.value, d.date
from tableb b cross join
(select distinct date from tablea a) d
where not exists (select 1 from tablea a where a.date = d.date and a.value = b.value)
Upvotes: 2