I have a sql problem that i can't figure out to solve in MySql:
Ok, I have 3 tables. One called "images", another called "categories" and the last called "bindings".
The "images" table contains a list of image names.
id - name
1 - Man
2 - Woman
3 - Child
4 - Dog
5 - Cat
6 - Banana
7 - Car
The "categories" table contains a list of different categories; which can be used for the images.
id - name
1 - Family
2 - Animals
3 - Humans
The "bindings" table contains a list of all those images that is stored in the categories. (two id numbers)
imageid - catid
1 - 1
2 - 1
3 - 1
4 - 1
5 - 1
4 - 2
5 - 2
1 - 3
2 - 3
3 - 3
Ok, it’s pretty simple to join these tables and select all images that e.g. are in the category "Animals":
SELECT images.name FROM images,categories,bindings WHERE categories.id=2 AND images.id=bindings.imageid AND categories.id=bindings.catid
So the problem is:
How do I select all those images that are not in any categories? The query should return "Banana" and "Car".