`SELECT * FROM Post
WHERE Tid = Id
ORDER BY Time
LIMIT 0,1`
`SELECT * FROM Post
WHERE Tid = Id
ORDER BY Time
LIMIT start,offset;`
Can I use only one SELECT to complete this? Just like
`SELECT * FROM Post
WHERE Tid = Id
ORDER BY Time
LIMIT 0,1 and start,offset;`
In this case combine the 2 sql statements in a union, since you cannot provide multiple limit clauses in a single select:
SELECT * FROM Post LIMIT 1,2
UNION ALL
SELECT * FROM Post LIMIT 5,6;
However, I would add an order by clause to the 2 select statements just to make 100% sure you know which records will be selected.
UPDATE: Technically you could do this in a single statement using a running counter and filtering on the counter in where. However, that would not really be a good idea from performance wise, since mysql would have to loop through all records within the table. It cannot know which records would satisfy the criteria. Limit clauses are better optmised.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments