The answer depends a great deal on how well organized your data is and the query itself.
For example, look at the query you have in the question:
SELECT rank, COUNT(id) FROM tablename GROUP BY rank
The first thing I think about with this query is whether the table is properly indexed.
OBSERVATION #1
If tablename had no indexes, a full table scan would be required.
OBSERVATION #2
If tablename had an index on rank, you still get a full table scan because of the MySQL Query Optimizer ruling out the use of the index because of factors such as key distribution and the possibility of having to lookup each id for every rank during a full index scan.
OBSERVATION #3
If the table had a compound index of (rank,id), then you can a full index scan. In most cases, a full index scan that never references the table for non-indexed columns would be faster than a full index scan that does (See OBSERVATION #2)
OBSERVATION #4
If the query was written slightly different
SELECT rank, COUNT(1) FROM tablename GROUP BY rank
then an index on just the rank column would suffice and produce a full index scan.
CONCLUSION
In light of these observtions, it is definitely a thing of beauty to present to the MySQL Query Optimizer two things:
- a good query
- proper indexes for all tables in the query
In retrospect, it is also good to give the MySQL Query Optimizer as much of an advantage upfront as possible.
In terms of operation
SELECT id,name,description FROM tablename LIMIT 1000,25
SELECT id,name,description FROM tablename LIMIT 25 OFFSET 1000
there is absolutely no difference in the statements
siride's comment:
from https://dev.mysql.com/doc/refman/5.6/en/select.html
For compatibility with PostgreSQL, MySQL also supports the LIMIT row_count OFFSET offset syntax.
is exactly the point.
LIMIT 1000,25
means LIMIT 25 OFFSET 1000
From the same Documentation
LIMIT row_count
is equivalent to LIMIT 0, row_count
YOUR ACTUAL QUESTIONS
- Does this actually do the same or is my understanding wrong?
- Is one slower/faster in larger tables
Since both queries are the same, there is no difference
- Does the result of offset change when I do WHERE column=1 (say column has >100 different values)
- Does the result of offset change when I do ORDER BY column ASC (asuming it has random values)
Using LIMIT
does not change any result sets. They simply navigate within the result set.
This query
SELECT id,name,description FROM tablename ORDER BY id LIMIT 1000,25
would be different from
SELECT * FROM (SELECT id,name,description FROM tablename LIMIT 1000,25) A ORDER BY id;
because the LIMIT is being applied at a different stage.
The first query returns nothing if tablename has less 1000 rows
The second query returns nothing if the subquery has less 1000 rows
CONCLUSION
You will have to sculpt the query to make sure you are sorting data at the right stage
Best Answer
You're limiting the resultset of the aggregate function
count()
, which will always return 1 row. IE: It's limiting the output of thecount(*)
function, rather thanLIMIT
ing justFROM data WHERE datetime < '2015-09-23 00:00:00'
.Basically:
FROM data WHERE datetime < '2015-09-23 00:00:00'
count(*)
s themLIMIT
s thatcount
I suspect you're wanting it to do this:
As this is basically an existence check, one could also do: