sqlite3 data.db 'SELECT * FROM employees ORDER BY CAST(salary AS INTEGER) DESC LIMIT 2;'

Category: Data Science & Analysis

sqlite3 data.db 'SELECT * FROM employees ORDER BY CAST(salary AS INTEGER) DESC LIMIT 2;'

Sort by salary numerically and take the top 2

SQLite's import tool stores values as TEXT, so sorting a numeric-looking column lexicographically puts 9 before 100. CAST(salary AS INTEGER) converts the text to a number for a true numeric sort. The DESC keyword orders descending and LIMIT 2 keeps the top two rows. This CAST pattern is mandatory whenever imported columns sort wrongly.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.