I have this table:
item year
---- ----
1 1999
2 1999
3 1999
2 2000
4 2000
2 2001
3 2001
4 2001
5 2001
And I need this result (with 1999 selected)
item year
---- ----
4 2000
4 2001
5 2001
To sum up, I need to obtain new items which aren’t in 1999, but which are defined in another different year (this is for adding them with another query later).
I’m using an old MySQL version and I’m not able to use subqueries. Is there any compatible solution?
What about something like this
In “english” it means, select all the items from my table. Then for each item try to find if they are in the table with the year 1999, else put NULL.
Then you just have to say “keep the elements that do not have a matching element in t2.
Not sure if my explanation is better anyway
EDIT: you of course need to replace
tablewith the name of your own table. I tested it on a small example and it seems to work.EDIT2 : If you look at the result of the LEFT JOIN you would have something like this :
Then if you add
WHERE t2.item IS NULLyou only keep the ones not having a year 1999 in the table.Is it a better way to understand it?