SQL Server Window Functions: RANK, LAG, and LEAD
Compare a row with preceding and following rows without a complicated self join.

A space to connect knowledge, one line of code a day.
Discover tutorials, ideas, and notes from a learning journey.
Build a focused web pentest plan with clear authorization, realistic objectives, controlled testing, and evidence that developers can use.
Compare a row with preceding and following rows without a complicated self join.
Compare OFFSET FETCH pagination with older approaches using TOP and subqueries.
SQL databases store raw values, but real reports rarely display them exactly as stored. Names may need to be capitalized, prices rounded, and dates formatted in a friendlier way. SQL provides built-in functions that transform values directly inside a query, so the database returns exactly what your application or report needs. In this tutorial, you […]
A SELECT statement is not limited to returning columns exactly as they are stored. You can compute new values on the fly — the total price of an order line, a discount, a tax amount, the age of a record, or the concatenation of a first and last name. These calculations happen inside the database […]
When you write SQL queries, the column names in your result often come straight from the table definition. Names such as unit_price or order_date are useful in the database, but they may look technical in a report, or they may collide when you join two tables that both contain a column called id. SQL solves […]
When you filter rows in SQL, you often need to match a value against a list of options, check whether it falls within a range, or exclude rows that satisfy a condition. Chaining many AND/OR comparisons for these cases quickly becomes hard to read. SQL provides three operators — IN, BETWEEN, and NOT — that […]
Stay curious. There is always something new to learn.
Writer and founder of Diary Coding — sharing notes, tutorials, and experiences about programming for anyone who wants to keep learning.