
4.7K
AS💡 SQL Interview Question:
👉 How do you display ODD-numbered records from a table in SQL?
This is a common SQL interview question to test your understanding of ROW numbering and filtering logic.
Here’s the clean SQL query 👇
SELECT *
FROM (
SELECT e.*,
ROW_NUMBER() OVER (ORDER BY employee_id) AS rn
FROM employees e
) t
WHERE rn % 2 = 1;
🎯 Explanation:
ROW_NUMBER() assigns a sequential number to each row
ORDER BY employee_id defines the row order
% 2 = 1 filters only odd-numbered rows
Subquery is required because window functions cannot be directly used in WHERE
Useful for pagination and alternate row selection
✅ Perfect for:
✔️ SQL Interviews
✔️ Backend Developers
✔️ Data Analysts
✔️ Java + Spring Boot Learners
✔️ Reporting & Pagination Logic
👉 Save this post for SQL revision
👉 Follow @ashokitschool for more SQL + Java + Full Stack content
#SQLInterviewQuestions #SQLTips #OddRecords #RowNumberSQL #AshokIT
@ashokitschool










