I am struggling with some sql and could use some help. I am sure it’s pretty novice stuff for a lot of people.
Here is an example:
I am trying to select all the pictures that are not in an album, when the albumid is supplied.
The tables
Picture table
pictureid
picturename
Album_Picture Association Table
albumpictureid
albumid
pictureid
Album Table – I don’t think this table needs to be referenced in the SQL.
albumid
albumname
I am assigning pictures to an album, and want to just display the pictures that havent already been assigned.
Extra credit: What would be even better is if I could select all the pictures in the table and be able to know which ones are in the album already, instead of omitting them from the returned data.
Then I could still show the image and just not allow it to be assigned.
Hope that all makes sense.
Thank you for any help.
using MYSQL 5
For your first question, this query will return you the pictures where there doesn’t have an association inside of your
album_pictureassociation table.A simple way of returning both is to add another column, performing two queries (one to give you the assigned pictures and one to give you the unassigned pictures), and getting the union of both.