I’m sorry if this is a newbie question, but it seems I don’t get why this doesn’t work like I would like:
mysql> select t.id,t.date_fin_val,tc.date_fin_val
from tiers t
join tiers_critere_int tc on tc.id_tiers=t.id
where (t.date_fin_val is null) and (tc.date_fin_val is null);
+----+---------------------+---------------------+
| id | date_fin_val | date_fin_val |
+----+---------------------+---------------------+
| 1 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 1 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 1 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
+----+---------------------+---------------------+
3 rows in set (0.00 sec)
mysql> select t.id,t.date_fin_val,tc.date_fin_val
from tiers t
left outer join tiers_critere_int tc on tc.id_tiers=t.id
where (t.date_fin_val is null) and (tc.date_fin_val is null);
Empty set (0.00 sec)
mysql>
I thought that “left outer joins” means: “if there is no result on the right side, but one on the left, go on anyway with the one on the left and put “null” values on the right.
If I were right, the second query with “left outer join” instead of “join” should return values. But it doesn’t. Why?
Here are my datas:
mysql> select * from tiers t where date_fin_val is null;
+----+---------------------+--------------------+
| id | date_fin_val | est_tiers_physique |
+----+---------------------+--------------------+
| 1 | 0000-00-00 00:00:00 | 1 |
+----+---------------------+--------------------+
1 row in set (0.00 sec)
mysql> select * from tiers_critere_int where date_fin_val is null;
+----+---------------------+----------+------------+---------+
| id | date_fin_val | id_tiers | id_critere | critere |
+----+---------------------+----------+------------+---------+
| 1 | 0000-00-00 00:00:00 | 1 | 2 | 86 |
| 2 | 0000-00-00 00:00:00 | 1 | 6 | 170 |
| 3 | 0000-00-00 00:00:00 | 1 | 7 | 65 |
+----+---------------------+----------+------------+---------+
3 rows in set (0.00 sec)
mysql>
Thank you very much!
My results are correct with you data and queries.
Now if you insert an empty string you will have: