Skip to content
Advertisement

SQL query returns values when selecting multiple columns, but no data when selecting only one column

I can’t get data to return when selecting only one column. This column is an integer format with a column name of “date”. I’m using SQLite3.

Outputs table.txt

justColumn.txt

I’d expect both queries to return the same data in the first column, but that’s not what’s happening. What is?

Advertisement

Answer

From the documentation:

If a SELECT statement that returns more than one row does not have an ORDER BY clause, the order in which the rows are returned is undefined.

I’m able to reproduce what you’re seeing with this table:

First query:

Second query:

The second one pulls results from an index with the requested column instead of the full table, and the rows in that index are returned in a different order than the ones in the table, thus different results. I imagine the situation is similar for your table.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement