---
title: "How to count number of rows before an ID in SQL Server"  
description: "How to count number of rows before an ID in SQL Server"  
author: "Anonymous User"  
published: 2014-02-03  
updated: 2014-02-03  
canonical: https://www.mindstick.com/forum/1948/how-to-count-number-of-rows-before-an-id-in-sql-server  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# How to count number of rows before an ID in SQL Server

I need to [count](https://www.mindstick.com/forum/157774/selecting-count-with-distinct) the total number of rows in a [table](https://www.mindstick.com/articles/43918/how-to-design-table-using-bootstrap) before the certain [row](https://www.mindstick.com/forum/1212/this-row-already-belongs-to-this-table) ID.

I have this [query](https://www.mindstick.com/blog/202/sub-query-in-sqlserver)

[select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) count (ClientID)

FROM [Seek].[dbo].[seekClient]

where ClientID < '12'

which [works fine](https://answers.mindstick.com/qa/115732/my-software-works-fine-on-windows-10-but-crashes-on-windows-11-why) for the case of [integer](https://answers.mindstick.com/qa/113667/write-code-for-roman-to-integer) [primary key](https://www.mindstick.com/blog/214/primary-key), but I am not sure how to do that in case of [GUID](https://www.mindstick.com/forum/12585/cast-the-value-returned-from-user-identity-getuserid-to-make-it-a-guid) ??

Kindly help me in this case.

Thanks

## Replies

### Reply by Pravesh Singh

Hi Ben,\

You should use a different column (not id) that defines what you mean by 'before'. It might be, for example, a 'DateOfCreation', 'creation_date' etc. column.

\


---

Original Source: https://www.mindstick.com/forum/1948/how-to-count-number-of-rows-before-an-id-in-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
