0

So I'm trying to display the titles where the number of actresses are 91, and from what I understood, LIMIT 1 should limit the number of ROWS to 1. But here, I'm actually getting 2 titles back that both have 91 actresses playing in it. Why does LIMIT 1 not limit the number of rows to 1 here?

Thanks in advance!

SELECT title, COUNT(*) c
FROM title_100k AS T
JOIN cast_info_100k AS CI ON CI.movie_id = T.id
JOIN role_type AS R ON R.id = CI.role_id
WHERE R.id = 2
GROUP BY(t.id))
SELECT title FROM tempTable WHERE c IN
(SELECT c from tempTable 
EXCEPT SELECT c from tempTable WHERE c IN (SELECT c from tempTable WHERE c > 91) ORDER By c desc LIMIT 1);```
jarlh
  • 42,561
  • 8
  • 45
  • 63
JakeDrone
  • 173
  • 1
  • 9

1 Answers1

1

It might because your LIMIT 1 is inside

(SELECT c
       from tempTable EXCEPT SELECT c
       from tempTable
       WHERE c IN (SELECT c from tempTable WHERE c > 91)
       ORDER By c desc
       LIMIT 1)

instead of outside

(SELECT c
       from tempTable EXCEPT SELECT c
       from tempTable
       WHERE c IN (SELECT c from tempTable WHERE c > 91)
       ORDER By c desc
       ) LIMIT 1

But you should check this answer How do I limit the number of rows returned by an Oracle query after ordering? because with newer version of Oracle, there are new options to limit the number of results.

Pilpo
  • 1,236
  • 1
  • 7
  • 18