I’m working in a C# SQLite library (SQLite-net) that doesn’t seem to support row value comparisons like this:
SELECT * FROM table WHERE (lastname, firstname) > ('Doe', 'John')
I get an error message at the first comma. Is there a long form way of doing the same comparison that could be compatible with older SQLite implementations? I’m no expert in SQL but I’ve tried a few ways of comparing the fields individually and in combination and haven’t been able to figure it out. Either records get included or excluded incorrectly. I tried searching for an answer but I’m not sure how to formulate the question so I haven’t found anything. Any suggestions would be appreciated.
Advertisement
Answer
You can use two comparisons:
WHERE lastname > 'Doe' OR (lastname = 'Doe' AND firstname > 'John')
Some databases do support tuple comparisons, but older versions of SQLite did not.