SQL query fixed to select registration properly