A problem with 'where'


A problem with 'where'

Hi, i am fresh in sql and teradate. When i used ‘where’  to filter the data from AUG, 2004 

WHERE a.num_month<>8 and a.num_year<>2004

The result seems all the data from AUG in different years and from 2004 including all the months are excluded.

Why this happened? Thanks.

Senior Apprentice

Re: A problem with 'where'

Well, this is exactly what you wrote: No data from the year 2004 and no data from any august :-)

You want either a.num_month<>8 OR a.num_year<>2004 or NOT(a.num_month = 8 AND a.num_year = 2004), the latter is a bit easier to understand, see https://en.wikipedia.org/wiki/De_Morgan%27s_laws

If you run Explain (F6) you will see that both result in the same search conditions.