I have the following table:

I need to select penultimate record matching some probID and studentID. How should I do that?
SELECT * FROM tbl
WHERE (probID = 2) AND (studentID = 2)
ORDER BY id DESC
LIMIT 1 OFFSET 1
PS: This will not return any result for (probID, studentID) = (2,13), because no penultimate record exists for this combination. If this is not desired, you will need to specify what should happen in this case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With