I am creating a basic ASP.net blog home page. I have two tables (structure given below). I need data from these tables for pagination so I used offset and skip in the query itself.
The tables are:
Table - Blog:
Id(primary),
Description,
Data,
CreatedById,
CreatedDate,
ImageUrl,
IsDeleted,
Tags,
StatusId(value = 1 for draft and 2 for publish)
Table - BlogCategories:
Id,
BlogId(foreign key to table 1),
CategoryId
I already have data in these tables. I am using the following query to fetch the data
Select *
from Blog b inner join
BlogCategories bc
on b.Id = bc.BlogId
where b.StatusId = 2 and bc.CategoryId = 2 and b.IsDeleted = 0
ORDER BY b.CreatedDate desc
OFFSET 73 ROWS
FETCH NEXT 9 ROWS ONLY;
This query is returning 0 rows but if I remove the statusId and CategoryId from the where clause the the query returns certain number of rows.
The expected result is:
Am I doing something wrong or is there a better way of doing it. Please help me with this. Thank you.