Shayal Singh
Shayal Singh

Reputation: 69

How to Select the lowest record but not the lowest

Records in database:

1
5
6
7
8
10

$select_query = "SELECT * FROM  images_tbl where images_id = $NextID ORDER BY images_id DESC LIMIT 1";

so if $NextID is 10 the next lowest record should be 8 not 1

Upvotes: 0

Views: 52

Answers (2)

hofan41
hofan41

Reputation: 1468

$select_query = "SELECT * FROM  images_tbl ORDER BY images_id ASC LIMIT 1,1";

Upvotes: 1

G B
G B

Reputation: 1462

you don't want the one = to $nextID, you want the next one "down".

$select_query = "SELECT Top 1 * FROM  images_tbl where images_id < $NextID ORDER BY images_id DESC 

Upvotes: 1

Related Questions