Problem constructing a query [SOLVED] |
[eluser]Unknown[/eluser]
First off, I'm pretty new to SQL/MySQL so pardon me if this is retardedly obvious. I'm having a problem constructing a query for a MySQL database. I have a site that revolves around users voting on photos. Right now, it selects a random photo from the database for users to vote on. However, I want to change it so that it only selects photos that users haven't actually voted on. Obviously, saving the votes is trivial, but I'm having problems selecting new photos that a user hasn't voted on. tl;dr version: Basically, what I want to do is select all the photos a given user has not voted for. There are two tables, one with the photos, and another with all the votes. Here are abbreviated versions of the DESCRIBE output for each one. Photos: Code: +----------+------------------+------+-----+---------+-------+ Code: +----------+-------------+------+-----+---------+-------+ Code: (SELECT id FROM users) EXCEPT (SELECT id FROM votes WHERE username = 'username')
[eluser]JayTee[/eluser]
I made the assumption that the id field in your 'votes' table corresponds to a photo's id field: Code: SELECT photos.id
[eluser]Unknown[/eluser]
[quote author="JayTee" date="1235912280"]I made the assumption that the id field in your 'votes' table corresponds to a photo's id field: Code: SELECT photos.id Yes they do correspond. And thank you! That worked perfectly. |
Welcome Guest, Not a member yet? Register Sign In |