Posted By

Jamie on 11/12/10


Versions (?)

MySQL Join on NOT Condition

 / Published in: MySQL

This was a strange case where I had to select all the items that were NOT assigned to a user. The data structure assumes that there is a 1 to 1 relationship between a user and an item. This is a simplified version of the query, but it's one of those queries that takes a while to figure out.

  1. SELECT, FROM items LEFT OUTER JOIN users ON users.item_id = WHERE users.item_id IS NULL

Report this snippet  

You need to login to post a comment.