If I specify a number, say 5, what query will give me all the rows after the 5th row? Like,
SELECT * FROM table WHERE 1=1;
only I want it to exclude the top 5. Thanks.
If I specify a number, say 5, what query will give me all the rows after the 5th row? Like,
SELECT * FROM table WHERE 1=1;
only I want it to exclude the top 5. Thanks.
Use the limit with a very high number as the second argument.
select * from myTable limit 5,18446744073709551615;
From MySQL Docs:
To retrieve all rows from a certain offset up to the end of the result set, you can use some large number for the second parameter. This statement retrieves all rows from the 96th row to the last:
SELECT * FROM tbl LIMIT 95,18446744073709551615;
BTW: You don't need WHERE 1=1
. It doesn't add any value to the query, just clutter.
SELECT * FROM table ORDER BY somecolumn LIMIT 5,1000
http://dev.mysql.com/doc/refman/5.1/en/select.html
[LIMIT {[offset,] row_count | row_count OFFSET offset}]
Are you looking for LIMIT?
SELECT * FROM table LIMIT 5,9999999
The second parameter to limit is just a large number to get all rows. Adjust accordingly.
If you have a column whose values can be ordered (and are unique), say ID1, You can do it in pure SQL (e.g. not using the MySQL specific LIMIT) as follows (Syntax is Sybas-ey, may need to tweak table alias and joins to work on mySQL):
SELECT * FROM table WHERE ID1 not in
-- SELECT FIRST @N ROWS IN ACCENDNING ORDER
(SELECT t1.ID1 FROM table 't1', table 't2'
WHERE t1.ID1 < t2.ID2
GROUP BY t1.ID1
HAVING count(*) <= @N)