Edited
======

I'm not asking How to write good query but those 3 queries return same results.

**Query 1**

```
SELECT v1.id
FROM (
    SELECT DISTINCT t1.id
    FROM t1 LEFT JOIN t2 ON t1.id = t2.id
    WHERE t2.id IS NULL
) v1 INNER JOIN (
    SELECT DISTINCT t3.id
    FROM t3 LEFT JOIN t4 ON t3.id = t4.id
    WHERE t4.id IS NULL
) v2 ON v1.id = v2.id;

```

**Query 2**

```
SELECT DISTINCT t1.id
FROM (t1 LEFT JOIN t2 ON t1.id = t2.id)
    INNER JOIN (t3 LEFT JOIN t4 ON t3.id = t4.id) ON t1.id = t3.id
WHERE t2.id IS NULL AND t4.id IS NULL;

```

**Query 3**

```
SELECT DISTINCT t1.id
FROM t1 LEFT JOIN t2 ON t1.id = t2.id
    INNER JOIN t3 ON t1.id = t3.id LEFT JOIN t4 ON t3.id = t4.id
WHERE t2.id IS NULL AND t4.id IS NULL;

```

Queries are not hard coded by programmer but generate dynamically by user input.

For example when user inserts `find id in t1 (but not in t2) and in t3 (but not in t4)`, his indention is `Query 1`. But currently my program generates `Query 3` and it looks like OK. I'm wondering this query has a bug in some cases, so that should be changed like `Query 2` or `1`.

User input (shown above) is just example and converting user input to JOIN statement is difficult at last to me.

Thanks in advanced.