Note: you can find my previous question and its answer here - MySQL: Writing a complex query
I have 3 tables.
Table Words_Learned
contains
I've read that question again and notice it is much more complicated.
First of all you want to show words. And whether you show a word depends on that word and all before-learned words (and the articles they appear in).
So with these words learned:
word order Octopus 3 Dog 2 Spoon 1 (i.e.first learned)
And these articles:
article contains Octopus contains Dog contains spoon unknown words A yes yes yes 5 B yes yes no 11 C yes no yes 15 D no yes yes 2 E no yes no 0 F no no yes 8 G no no no 3 H no no no 20
You ...
So you show "Dog" and "Spoon" and not "Octopus". And if there were not only two matches, but thousand, you would show the first 100 and then stop.
Given this algorithm, we can conclude:
The query:
select idwords
from words_learned
where userid = 123
and not exists
(
select w.idarticle
from words w
left join words_learned l on l.idwords = w.idwords and l.userid = 123
group by w.idarticle
having sum(l.idwords is null) > 10 and max(l.`order`) = words_learned.`order`
)
order by `order` desc
limit 100;
Here is an SQL fiddle: http://sqlfiddle.com/#!2/19bf8/1.