I have this table:
USERID CHECKTIME CHECKTYPE
1 2018-10-21 09:01:08.000 I
1 2018-10-21 10:00:51.000 I
1 2018-10-22 13:19:23.000 1
1 2018-10-22 15:56:11.000 0
1 2018-10-22 16:51:27.000 O
I need select two rows like this:
userid in out
1 2018-10-22 13:19:23.000 2018-10-22 15:56:11.000
but same the date and same userid date and userid come from post page php database is sqlserver connection with php
SELECT TOP 1 checktime, userid, checktype
FROM CHECKINOUT
WHERE userid = '$idd'
AND CAST(checktime As DATE)='$x'
AND checktype='1'
UNION ALL
SELECT TOP 1 checktime, userid, checktype
FROM CHECKINOUT
WHERE userid='$idd'
AND CAST(checktime As DATE)='$x'
AND checktype='0'