Skip to content
Advertisement

SQL query to find the second occurrence of an element in a database

For example I have this table:

I want to get the row where the PersonID occurs for the second time.

So the desired output needs to be (for one of the person ID) :

What would be the query for this scenario?

Advertisement

Answer

Use ROW_NUMBER() Function For this scenario

Please Refer this link for how to use this function different way ROW_NUMBER()

Query In > SQL Server (T-SQL)

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement