I have four tables
Tag=>id,tag_name Image=>Id,Image_name TagImage=>Id,tag_id,Image_id ImageStudent=id,Image_id,student_id
And I want to find a record using student id and tag name. What relationship do I use?
I have four tables
Tag=>id,tag_name Image=>Id,Image_name TagImage=>Id,tag_id,Image_id ImageStudent=id,Image_id,student_id
And I want to find a record using student id and tag name. What relationship do I use?
Might be better to use a UNION with a query like this, here it is with the necessary joins.
SELECT Image.* FROM Image
INNER JOIN ImageStudent ON Image.Id = ImageStudent.Image_id
LEFT OUTER JOIN TagImage ON Image.Id = TagImage.Image_id
INNER JOIN Tag ON TagImage.Id = Tag.Id
WHERE Tag.tag_name = 'foo' AND ImageStudent.student_id = 42;