- #1
DaveC426913
Gold Member
- 22,497
- 6,168
I've got 3 tables:
Pics - table of my pictures
Categories - table of categories that pictures will fall into
PicsCategories - a many-to-many table relating pictures to categories. So the primary key of this table consists of a pic field and a category field
So now I want to provide a couple of categories as params and have it return all rows from the Pics table that are in those categories.
So if I supply Category1=2 OR Category2=3 (females and/or parents)
It should return Pic rows:
2
3
4
I'm looking at JOIN but JOIN is meant to extract data from two tables. I do not need ANY data from the PicsCategories table.
This is what I want:
SELECT UNIQUE(*) FROM Pics WHERE id=(SELECT Pic FROM PicsCategories WHERE Categories=2 OR Categories=3)
Pics - table of my pictures
Categories - table of categories that pictures will fall into
PicsCategories - a many-to-many table relating pictures to categories. So the primary key of this table consists of a pic field and a category field
So now I want to provide a couple of categories as params and have it return all rows from the Pics table that are in those categories.
Code:
Table Pics
id Name
1 Bob
2 Mary
3 Jill
4 Jane
Table Categories
id Name
1 Male
2 Female
3 Parent
Table PicsCategories
Pic Cat
1 1
1 3
2 2
3 2
3 3
4 2
4 3
It should return Pic rows:
2
3
4
I'm looking at JOIN but JOIN is meant to extract data from two tables. I do not need ANY data from the PicsCategories table.
This is what I want:
SELECT UNIQUE(*) FROM Pics WHERE id=(SELECT Pic FROM PicsCategories WHERE Categories=2 OR Categories=3)
Last edited: