How to Find the Closest Subset Sum with SQL

I've stumbled upon this very interesting question on Stack Overflow, recently. Its title is: [How to] compare a number with sum of subset of numbers In this article, we'll compare the user's imperative approach to the extremely elegant (Oracle) SQL approach. We'll be making use of any combination of these awesome SQL features: Window functions … Continue reading How to Find the Closest Subset Sum with SQL

The Difference Between ROW_NUMBER(), RANK(), and DENSE_RANK()

One of the best features in SQL are window functions. Dimitri Fontaine put it bluntly: There was SQL before window functions and SQL after window functions If you're lucky enough to be using any of these databases, then you can use window functions yourself: CUBRIDDB2FirebirdH2InformixMariaDBMySQLOraclePostgreSQLSQLiteSQL ServerSybase SQL AnywhereTeradata (source here) One of the most obvious … Continue reading The Difference Between ROW_NUMBER(), RANK(), and DENSE_RANK()

Stop Trying to Emulate SQL OFFSET Pagination with Your In-House DB Framework!

I'm pretty sure you've gotten it wrong in numerous ways, so far. And you probably won't get it right any time soon. So why waste your precious time on SQL tweaking, when you could be implementing business logic? Let me explain... It hasn't been until the recent SQL:2008 standard that what MySQL users know as … Continue reading Stop Trying to Emulate SQL OFFSET Pagination with Your In-House DB Framework!