user1683645
user1683645

Reputation: 1579

limiting number of elements in a result set

I'm trying to limit the number of elements in my result set by setting a limit to my sql logic. I have two seperate functions to achieve what I want. The first one has a limit I've set manually e.g 0, X. The second function has two extra arguments that is min and max and these are set as the limit. But when the min and max are e.g 7, 14 it gives me more elements then 7. There are no duplications in the result set since I have unique id's on each element and they check out. Also the integers passed to the sql function have the correct intervall.

What am I doing wrong?

"SELECT table1.*, table2.user_id FROM table1 LEFT JOIN table2 ON table1.col1 = table2.col2 
    WHERE table1.col1 = :param1 AND table1.col2 = 1 AND table1.col3 = 0 ORDER BY table1.col4 DESC LIMIT $min, $max";

Upvotes: 0

Views: 203

Answers (1)

Olaf Dietsche
Olaf Dietsche

Reputation: 74028

The syntax is SELECT Syntax is not

limit min, max

but

limit offset, row_count

so, limit 7, 14 says retrieve 14 rows at offset 7.

Upvotes: 4

Related Questions