This is probably something really easy but I cant figure it out at the moment.
Table Order
+----+---------+
| id | name |
+----+---------+
| 1 | Order 1 |
| 2 | Order 2 |
| 3 | Order 3 |
+----+---------+
Table Facturationdetails
+----+----------------+
| id | name |
+----+----------------+
| 1 | Transportation |
| 2 | Regular |
| 3 | Fixed |
+----+----------------+
Table Relation:
Table Facturationdetails
+----------+---------+
| order_id | fact_id |
+----------+---------+
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 2 | 2 |
| 2 | 3 |
| 3 | 2 |
+----------+---------+
Now I would like to find out for which order there are no fakturationdetails1(Transportation)
select to.order_id
from table_order to
join table_facturation tf
on tf.order_id = to.order_id
where tf.fakt_id != 1
But this will return all rows:
+---+---+
| 1 | 2 |
| 1 | 3 |
| 2 | 2 |
| 2 | 3 |
| 3 | 2 |
+---+---+
And I want the results to be:
Order 2 and Order 3.