Link to home
Start Free TrialLog in
Avatar of dimensionav
dimensionavFlag for Mexico

asked on

How to get previous record before the last one?

HI

I have a table like this named Profiles:

!dMain, IdProfile, Qty
1                17        20
2                17        33
3                18        25
4                18        30
5                17        10
6                17         5

I want to get the previuous record regarding the last added one per each IdProfile using SQL, something like this:

!dMain, IdProfile, Qty
3                18        25
5                17        10

Thanks in advance.
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

The idMain values are not necessarily sequential, correct?  In other words, can the previous row may be several ids back?
ASKER CERTIFIED SOLUTION
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dimensionav

ASKER

The idMain values are not necessarily sequential, correct?  In other words, can the previous row may be several ids back?
 YES, can be several ids back.

Kevin, just a question, does your solution works for MySQL?
Thanks for everything.
The solution I gave is specific to MySQL.  It would be different syntax for other languages.  The article I wrote explains the different implementations across different SQL platforms in case you need to create something similar in other systems.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial