Q. Write a SQL query to fetch only odd rows from table.

Answer: Odd rows can be achieved by using Row_number in SQL server-

SELECT E.EmpId, E.Project, E.Salary
FROM (
SELECT *, Row_Number() OVER(ORDER BY EmpId) AS RowNumber
FROM EmployeeSalary
) E
WHERE E.RowNumber % 2 = 1

Leave a Reply

Your email address will not be published. Required fields are marked *