# SQL Query - nested WHERE clause?

**URL:** <https://forum.kirupa.com/t/sql-query-nested-where-clause/218327>\
**Category:** programming\
**Created:** [March 6, 2007, 8:20pm UTC](https://forum.kirupa.com/t/sql-query-nested-where-clause/218327 "2007-03-06T20:20:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![DHDesign](https://avatars.discourse-cdn.com/v4/letter/d/b19c9b/32.png) [@DHDesign](https://forum.kirupa.com/u/DHDesign)\
**Post date:** [March 6, 2007, 8:20pm UTC](https://forum.kirupa.com/t/sql-query-nested-where-clause/218327/1 "2007-03-06T20:20:20Z")

</div>

i have the following tables:

## table1

ID  
Stat

## table2

ID  
Date

I need to display all items in table1 with a Stat of 5, 10 or 20 with their associated Date from table2, BUT if the Stat from table1 is equal to 10, then I need to check whether the associated Date from table2 is equal to 02/04/2007…if so, I need those records also NOT displayed.

```auto

SELECT a.Stat, b.Date FROM table1 as a, table2 as b WHERE a.Stat IN (5,10,20)

```

That’s where I get stuck though…how do I tell the query that IF now the Stat we found is 10, also check the date from table2 and if that date is equal to 02/04/2007, take it out of the record display too?
