Query to search for 2 years and exclude 1

Viewed 57

My apologies for the oddly worded question as I wasn't quite sure how I would name the title without explaining the situation.

I am currently working with a vendor table which gives a unique ID to each vendor, but the table is not normalized.

For example the ID 100000003744450 appears multiple times in the table with a different data in each row.

There are many columns but the only ones that matter to me at the moment are the ID and the year column. I am attempting to find the vendors who have rows for 2013, 2014 but not 2015.

So far I have:

select * 
from table
where ls_d_yr = '2013'
   or ls_d_yr = '2014'

I need to filter this results by removing any of the vendors that have the year 2013/2014 and should not have any rows with 2015 listed.

Here are the column

enter image description here

enter image description here

5 Answers
Related