Junior Window Functions SQL & Databases

Write a query to find odd / even rows using ROW_NUMBER.

Short answer: Assign ROW_NUMBER() then filter rn % 2 = 1 for odd rows. Useful in puzzles; rare in production.

Sample solution

T-SQL
SELECT *
FROM (
    SELECT *, ROW_NUMBER() OVER (ORDER BY EmpId) AS rn
    FROM Employees
) t
WHERE rn % 2 = 1;
Clarify ordering — “odd rows” is meaningless without ORDER BY.
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details