I've two tables, basically like this:
images: id, otherinfo...
tags: id, imageid, otherinfo...
Now, I want to select everything in `images` that doesn't have an entry in `tags`
How might I go about that?
Such as...
SELECT * FROM `images` WHERE `images`.`id` is not in `tags`.`imageid`;
Is this easily done? Or should I add another row in the `images` table that says whether or not there have been tags added yet (big hassle)?
Select From `table1` Where NOT in `table2` ?? [Solved]
Moderator: General Moderators
Select From `table1` Where NOT in `table2` ?? [Solved]
Last edited by Skara on Wed Mar 21, 2007 8:16 pm, edited 1 time in total.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Aha! I had to change the *, though. As your query stands, for some reason images.id doesn't get selected--it winds up empty.
This works, though:
Thanks!
This works, though:
Code: Select all
SELECT `images`.`id`,`images`.`file`,`images`.`rating` FROM `images` LEFT JOIN tags ON images.id = tags.fileid WHERE tags.fileid IS NULL;- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US