Bug fix to SQL query giving wrong list of tags