MySQL Forums
Forum List  »  General

Re: combine this 2 simple querys into 1 query for performance.
Posted by: laptop alias
Date: September 14, 2011 12:55AM

There might be a simpler way but I think something like this could work...

SELECT * FROM ints;
+---+
| i |
+---+
| 0 |
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
| 9 |
+---+

SELECT i+(SELECT MAX(i) + i FROM ints)x,i FROM ints
UNION
SELECT i,i FROM ints
WHERE i > 7
ORDER BY x LIMIT 5;
+------+---+
| x    | i |
+------+---+
|    8 | 8 |
|    9 | 9 |
|    9 | 0 |
|   10 | 1 |
|   11 | 2 |
+------+---+

Options: ReplyQuote


Subject
Written By
Posted
Re: combine this 2 simple querys into 1 query for performance.
September 14, 2011 12:55AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.