fix for sql for activity logs to make less mysql specific

tested and fixed for postgresql