Skip to content

Instantly share code, notes, and snippets.

@johnreilly
Created December 8, 2008 20:56
Show Gist options
  • Save johnreilly/33606 to your computer and use it in GitHub Desktop.
Save johnreilly/33606 to your computer and use it in GitHub Desktop.
Subqueries are handled differently in sqlite3 and mysql?
Rails generates the same SQL, databases return different results.
Using sqlite3:
----------------
>> Person.count
SQL (0.2ms) SELECT count(*) AS count_all FROM "people"
=> 2
>> Person.all(:conditions => ['id NOT IN (?)', []])
Person Load (0.9ms) SELECT * FROM "people" WHERE (id NOT IN (NULL))
=> [#<Person id: 1, ...>, #<Person id: 2, ...>]
Using mysql:
----------------
>> Person.count
SQL (0.0ms) SELECT count(*) AS count_all FROM `people`
=> 2
>> Person.all(:conditions => ['id NOT IN (?)', []])
Person Load (0.0ms) SELECT * FROM `people` WHERE (id NOT IN (NULL))
=> []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment