![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, I have a table to store the login history of clients. One of the captured fields is the timestamp. I am trying to write a query to get all but the last row in the login history for a user. I thought something like this should work: SELECT * FROM LoginHistory L WHERE USER_ID like 'testuser (AT) company (DOT) com' HAVING L.TIMESTAMP< MAX(L.TIMESTAMP); This seems to select only the first row. Any idea why this is happening and how to do it correctly? Thanks |
#3
| |||
| |||
|
|
On 17-11-10 11:13, Mark Smith wrote: Hi, I have a table to store the login history of clients. One of the captured fields is the timestamp. I am trying to write a query to get all but the last row in the login history for a user. I thought something like this should work: SELECT * FROM LoginHistory L WHERE USER_ID like 'testu... (AT) company (DOT) com' HAVING L.TIMESTAMP< *MAX(L.TIMESTAMP); This seems to select only the first row. Any idea why this is happening and how to do it correctly? Thanks SELECT * FROM LoginHistory L WHERE USER_ID like 'testu... (AT) company (DOT) com' HAVING L.TIMESTAMP< *( * * * * SELECT MAX(M.TIMESTAMP) * * * * FROM LoginHistory M * * * * WHERE M.USER_ID like 'testu... (AT) company (DOT) com'); -- Luuk |
#4
| |||
| |||
|
|
I have a table to store the login history of clients. One of the captured fields is the timestamp. I am trying to write a query to get all but the last row in the login history for a user. I thought something like this should work: SELECT * FROM LoginHistory L WHERE USER_ID like 'testuser (AT) company (DOT) com' HAVING L.TIMESTAMP < MAX(L.TIMESTAMP); |
#5
| |||
| |||
|
|
On Nov 17, 10:27 am, Luuk<L... (AT) invalid (DOT) lan> wrote: On 17-11-10 11:13, Mark Smith wrote: Hi, I have a table to store the login history of clients. One of the captured fields is the timestamp. I am trying to write a query to get all but the last row in the login history for a user. I thought something like this should work: SELECT * FROM LoginHistory L WHERE USER_ID like 'testu... (AT) company (DOT) com' HAVING L.TIMESTAMP< MAX(L.TIMESTAMP); This seems to select only the first row. Any idea why this is happening and how to do it correctly? Thanks SELECT * FROM LoginHistory L WHERE USER_ID like 'testu... (AT) company (DOT) com' HAVING L.TIMESTAMP< ( SELECT MAX(M.TIMESTAMP) FROM LoginHistory M WHERE M.USER_ID like 'testu... (AT) company (DOT) com'); -- Luuk Thanks. Although is there a reason mysql can't / won't do this with just one select? |
#6
| |||
| |||
|
|
i | +---+ 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | +---+ |
|
i | +---+ 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | +---+ |
![]() |
| Thread Tools | |
| Display Modes | |
| |