SQLite passing multiple parameter in WHERE
You can do this with a join:
SELECT sqid, said, saname, satimestampFROM surveyanswer AJOIN ( SELECT sqid, hoid, max(satimestamp) as satimestamp FROM surveyanswer GROUP BY sqid) B ON A.sqid = B.sqid and A.hoid = B.hoid and A.satimestamp = B.satimestamp
Which is functionally like your original SQL but since you only care about time I believe this will work as well:
SELECT sqid, said, saname, satimestampFROM surveyanswer AJOIN ( SELECT max(satimestamp) as satimestamp FROM surveyanswer) B ON A.satimestamp = B.satimestamp
It doesn't appear that you are using the hoid
field for anything. So, I removed it. Does the following produce what you are looking for:
SELECT sa.sqid, sa.said, sa.saname, sa.satimestampFROM surveyanswer saWHERE sa.satimestamp IN ( SELECT max(subsa.satimestamp) FROM surveyanswer subsa WHERE sa.sqid = subsa.sqid)
If the hoid
field needs to be included in the where clause then try the following:
SELECT sa.sqid, sa.said, sa.saname, sa.satimestampFROM surveyanswer saWHERE sa.satimestamp IN ( SELECT max(subsa.satimestamp) FROM surveyanswer subsa WHERE sa.sqid = subsa.sqid AND sa.hoid = subsa.hoid)