Subtract time from 2nd row with the first

I have one table with one show data and other with dismiss data. So there are n number of show and dismiss data per session. I need to calculate time from one dismiss to another show in a session.

Hello,
Please post a create table script for each table, insert statements with a small sample of the data you're working with, a clear explanation of what output you want and I'm sure you will get some help.

This is the right code in sql :

SELECT TIMEDIFF(FIRSTTIME.timestamp,SECONDTIME.timestamp), FIRSTTIME.inputrate1 - SECONDTIME.inputrate1, FIRSTTIME.outputrate1 - SECONDTIME.outputrate1
FROM
((SELECT * FROM table HAVING timestamp = max(timestamp)) as FIRSTTIME,
(SELECT * FROM table ORDER BY TIMESTAMP LIMIT 1,1) as SECONDTIME)