1

Could anybody please help me with query

Lets say my table table has rows like 1,2,3,4,5,......50k I would like to select rows likely 1,3,5,....49997,49999 or 1,4,7...49997 Pls help me how to achieve this in sql and as well as in linq Thank you

ays_babes
  • 17
  • 1
  • 4

1 Answers1

0

SQL Server/MySQL/Postgresql/SQLite version using modulo division:

SELECT *
FROM your_table
WHERE id % 2 = 1;

SELECT *
FROM your_table
WHERE id % 3 = 1;

As jarlh mentioned in comment there is MOD(id, x) operator in standard SQL (not working in SQL Server/SQLite)

Community
  • 1
  • 1
Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275