Structure is:
CREATE TABLE current
(
id BIGINT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
symbol VARCHAR(5),
UNIQUE (id), INDEX (symbol)
) ENGINE MyISAM;
| id | symbol |
|---|---|
| 1 | A |
| 2 | B |
| 3 | C |
| 4 | C |
| 5 | B |
| 6 | A |
| 7 | C |
| 8 | C |
| 9 | A |
| 10 | B |
I am using the following
SELECT *
FROM current
WHERE id
IN
(
SELECT MAX(id)
FROM current
GROUP BY symbol
)
to return the last records in a table.
| id | symbol |
|---|---|
| 8 | C |
| 9 | A |
| 10 | B |
How can I return the next-to-last results in a similar fashion?
I know that I need
ORDER BY id DESC LIMIT 1,1
somewhere, but my foo is weak.
I would want to return
| id | symbol |
|---|---|
| 5 | B |
| 6 | A |
| 7 | C |