I've got a table with 3 columns: name
, lastname
and date
.
For example:
Name Lastname Date
Ab Ab 2008-07-01
Ab Ab 2006-06-23
Kb Kb 2008-07-01
Kb Kb 2007-06-03
I need to find the names of those who are assigned to 2008-07
and not to 2006-06
. So for this example the output will be:
Name Lastname Date
Kb Kb 2008-07-01
Kb Kb 2007-06-03
My code:
select Name, Lastname, YEAR(date), MONTH(date) from MyTable
where (YEAR(date) = 2008 AND MONTH(date) = 7) AND (YEAR(date) <> 2006 AND MONTH(date) <> 6)
It doesn't work well, because really nothing happen (it "blocking" for example all names with month = 6). I try to do it with UNION statement, but nothing work well.
Note, I need to do this without using a subquery.