I just learned how to use JOINS (so please be gentle ;) ), and wrote this query:

```
SELECT 1
FROM `T1` 
INNER JOIN `T2` ON `T1`.`T1_ID` = `T2`.`REQUIREMENT`
WHERE `T2`.`T1_ID` = XXX
  AND `T1`.`STATEMENT` = YYY
  AND `T2`.`REQUIREMENT` != 0 //last row does not work as intended!

```

It works perfectly without the last condition: if `T1_ID` from `T1` does match `REQUIREMENT` from `T2` for given `T1_ID` (XXX) - it does work. I wanted additional `STATEMENT` from `T1` to be match (YYY) - and it still does work.

But then I realized, that I need to exclude one cause: when `T2`.`REQUIREMENT` is equal to 0, I want this query to return 1 regardless of the JOIN formula. The problem is, that if `T2`.`REQUIREMENT` = 0, I know for sure that there will not be any `T1`.`T1_ID` entry that will match the JOIN requirements. So I understand, that this last condition has no right to work like I'd wish it was.

What I need is some kind of IF statement. Something that would work like:

```
SELECT 1 
    IF (`T2`.`REQUIREMENT`!=0) //if true, don't even go to join, and return 1
       OR (my previous join query)

```

The thing is, that I have no idea how to implement such IF statement into mysql. 

Any ideas? Thanks.

Sample data:

T1:

```
id   STATEMENT  T1_ID
1    irrelevant   1
2    irrelevant   5

```

T2:

```
id  T1_ID REQUIREMENT
1    1     0
2    2     0
3    3     1
4    4     3
5    5     4
6    6     5
7    7     6

```

Such setup should return 1 for `T1_ID` equal 1, 2, 3, 6. 

In addition, if it's even possible in single query, I'd like it to return 1 as well even if `T1` was empty, for all `T2`.`REQUIREMENT`=0 - in this case `T1_ID` equal 1, 2.