Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

macuser154

macrumors 6502
Original poster
Jan 17, 2009
372
0
UK
I don't really know where this would go. But does anyone know how I can use the limit parameter in SQL to only bring back 25% of the total amount of records?
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,852
9
USA
I'd probably just create a temp variable that calculates it
Code:
SET @quarter = (SELECT COUNT(*) FROM mytable) / 4;
SELECT * FROM mytable LIMIT ROUND(@quarter);
Haven't tested this though.
 

belvdr

macrumors 603
Aug 15, 2005
5,945
1,372
I'd probably just create a temp variable that calculates it
Code:
SET @quarter = (SELECT COUNT(*) FROM mytable) / 4;
SELECT * FROM mytable LIMIT ROUND(@quarter);
Haven't tested this though.

I wouldn't recommend that on a very large table. Talk about a resource hog with two full table scans.

I'd recommend limiting it to a distinct number. Using percentages, if the table has 100 rows, then you pull back 25. If it has 1,000,000, then you're pulling back 250,000, which is most likely not what the user wanted.
 

macuser154

macrumors 6502
Original poster
Jan 17, 2009
372
0
UK
I wouldn't recommend that on a very large table. Talk about a resource hog with two full table scans.

I'd recommend limiting it to a distinct number. Using percentages, if the table has 100 rows, then you pull back 25. If it has 1,000,000, then you're pulling back 250,000, which is most likely not what the user wanted.

This limiter would be used on a View, which tends not to have many records in it. Would that help keep the resource usage down?
 

belvdr

macrumors 603
Aug 15, 2005
5,945
1,372
This limiter would be used on a View, which tends not to have many records in it. Would that help keep the resource usage down?

A view is transparent and holds no actual data, so no it won't help. How many rows does this view contain?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.