View Full Version : LIMIT Query
Weirfire
Nov 2nd 2005, 1:39 pm
I would like to SELECT all values in a table starting at the 2nd result!
Anyone know a solution to this without doing a query like
SELECT X FROM Y LIMIT 2,47358927354
???
heapseo
Nov 2nd 2005, 2:09 pm
can u not just select them all and filter out the first result using php or whatever?
fooey
Nov 2nd 2005, 2:21 pm
here's an example for a different vendor with coldfusion sprinkled in, but you should get the idea, and I didn't feel like cleaning it up ;p
SELECT
an_id,
as_ShortName,
ac_name,
an_date,
an_link,
an_title,
an_description,
an_remote_id,
an_hasCache AS isCached
FROM ( SELECT TOP #PerPage# * FROM (
SELECT TOP #Evaluate(PerPage * PageNum)# MIN(an_id) AS MinID
FROM Archives_News
LEFT JOIN Archives_Sites ON as_id = an_as_id
LEFT JOIN Archives_Categories ON ac_id = an_ac_id
GROUP BY an_as_id, an_title, an_remote_id
ORDER BY MIN(an_id) DESC
) inner1
ORDER BY MinID
) inner2
INNER JOIN Archives_News ON MinID = an_id
LEFT JOIN Archives_Sites ON as_id = an_as_id
LEFT JOIN Archives_Categories ON ac_id = an_ac_id
ORDER BY an_id DESC
nevetS
Nov 2nd 2005, 2:32 pm
tiptopvillas is right. You need to parse out that record in your php script. The LIMIT clause allows you to set an offset value, but there is no way (that I know of) to use the LIMIT clause without limiting the rows returned.
Either that, or use your first solution and put a crazy high number in your rowcount parameter.
Weirfire
Nov 2nd 2005, 2:41 pm
Thanks guys. Just thought there might be an operator for the LIMIT command that could be used to select everything after a certain point.
JoeO
Nov 2nd 2005, 2:41 pm
Does this one record always change? or is there an ID you can use to exclude it?
Weirfire
Nov 2nd 2005, 2:45 pm
Nah the one I'm exluding is the newest 1 which will always be changing. The reason I'm excluding it is because it gets displayed at the top of the page.
Just do
select * from abigtablewithacrapfirstrecord
limit 1, -1
:D
Weirfire
Nov 2nd 2005, 2:52 pm
All I can say is well done dct :D {clap clap clap}
JoeO
Nov 2nd 2005, 7:58 pm
nice one, doesn't seem logical, but who can argue with results? ;)
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.