# How to count the number of rows of a table used in the query?

**URL:** https://forum.kirupa.com/t/how-to-count-the-number-of-rows-of-a-table-used-in-the-query/659281
**Category:** programming
**Created:** [June 12, 2023, 3:39pm UTC](https://forum.kirupa.com/t/how-to-count-the-number-of-rows-of-a-table-used-in-the-query/659281 "2023-06-12T15:39:55Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![polaryeti](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/polaryeti/32/19283_2.png) [@polaryeti](https://forum.kirupa.com/u/polaryeti)
#### Post date: [June 12, 2023, 3:39pm UTC](https://forum.kirupa.com/t/how-to-count-the-number-of-rows-of-a-table-used-in-the-query/659281/1 "2023-06-12T15:39:55Z")

</div>

I’ve this database.

> **[Northwind-Sample-Database-Diagram.pdf](https://brucebauer.info/assets/ITEC3610/Northwind/Northwind-Sample-Database-Diagram.pdf)**
>
> 151.66 KB

I want to find fourth lowest salary.

```auto
SELECT 
    *
FROM
    employees
ORDER BY salary DESC
LIMIT 1 OFFSET (Number_of_rows_of_table-3);

```

**I can solve this by using order by ASC pretty easily with LIMIT 1 OFFSET 3. I’m wondering if there’s an way to solve it via order by DESC?**

Here’s my try which didn’t work.

```auto
SELECT 
count(*) as no_of_rows_of_table, salary
FROM
    employees
ORDER BY salary DESC
LIMIT 1 OFFSET (no_of_rows_of_table-3);

```
