SQLSQL
#48

Swap Consecutive Seat IDs in SQL

MediumGoogle
Interview Question #48
Asked at Google

Write a SQL query to swap the `id` of every two consecutive students in a `seat` table. If the number of students is odd, the id of the last student is not swapped.

Input Table: seat
5 rows preview
idstudent
1Abbot
2Doris
3Emerson
4Green
5Jeames
Expected Output Structure5 rows
idstudent
1Doris
2Abbot
3Green
4Emerson
5Jeames
Interview Context

Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.

SQLPostgreSQL 15
Ready to execute

Click "Run Query" or press Ctrl + Enter to test your query.

Output will be verified against the test dataset.

Chat with us