Also you are using single quotes for <code>D3</code>. You should not be quoting column names. They should go unquoted. Single quotes and double quotes are used for completely different purposes in SQLite. The fact that you can sometimes get the 'right' result is a nasty historical artefact which only confuses people.