0

I have table A which includes all data based on a read date. For example:

Read Date----Data
1/1/2016-----3
1/2/2016-----10
1/3/2016-----42
1/4/2016-----16
12/25/2016----32
12/26/2016----12
12/27/2016-----8

From that data set, I created a query that looks at a list of off-peak holidays, as well as off peak days, and created a table from that. This table looks like:

Read Date ----- Data
1/1/2016---------3
1/2/2016---------10 
12/25/2016-------32

I need to create a query that will give me table A data EXCLUDING table B data. Which would look something like this:

Read Date ----- Data
1/3/2016---------42
1/4/2016---------16
12/26/2016-------12
12/27/2016--------8

I have tried different join, NOT IN, WHERE NOT, and many others, which would sadly just return all results from Table A or no results at all.

PS - I apologize for the formatting, new to all of this.

NOT IN, WHERE NOT, <>, LEFT JOIN, ISNULL

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786

1 Answers1

0

Use not exists:

select a.*
from a
where not exists (select 1
                  from b
                  where b.read_date = a.read_date and b.data = a.data
                 );
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • IT WORKED, thank you! Just out of curiosity, what does the 1 do? I'm very new to SQL and have been teaching myself here and there, slowly learning.. – user11416683 Apr 26 '19 at 17:08
  • @user11416683 . . . `exists` checks for the existence of rows. It does not care what is being `select`ed. `1` is about the simplest thing you can type. – Gordon Linoff Apr 26 '19 at 21:51