Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

mysql select where not equal value from another table

I have the following tables; image, user, vote

fields:

image -> id, total, status

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

vote -> user_id, image_id, vote

user -> id, name, pass, status

When a user votes on an image the ‘vote’ table will update with their user_id, the image they voted on (image_id) and their ‘vote’.

I want to query the table to show me all images that the current user has NOT voted for. Here is my query:

SELECT * FROM image, vote WHERE vote.image_id != image.id

>Solution :

SELECT 
  * 
FROM image
WHERE 
  id NOT IN (
    SELECT image_id FROM vote WHERE user_id = USER_ID_HERE
  )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading