If where selects how could i select, like every OTHER id? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

If where selects how could i select, like every OTHER id?

28th Sep 2016, 3:12 PM
SoundwaveOfBC
SoundwaveOfBC - avatar
2 Answers
+ 2
You use: SELECT * FROM example_1 WHERE ID !=1
1st Oct 2016, 10:30 PM
Deno Däumling
Deno Däumling - avatar
+ 1
Havent tested this but you could likely use a combination of ROW_NUMBER and the remainder operator - %. For example: WHERE (ROW_NUMBER % 2 = 0) should give you all records in even rows. WHERE (ROW_NUMBER % 2 = 1) should give you all records in odd rows. If you're using this to provide a "random" result you need to be aware this isn't random. A better way may be to SELECT TOP (# number of records) and ORDER BY newid(). This assigns a psudo-random id to each record and then sorts by tha random id and provides you with a pre-set number of results.
30th Sep 2016, 1:51 AM
Chris G
Chris G - avatar