SELECT
  CAST(ID AS VARCHAR) AS PATTERN_VALUE,
  PATTERN_NAME AS PATTERN_LABEL,
  PREFERENCE,
  QUERY AS PATTERN_QUERY_STRING
FROM
  TR_SEARCH_PATTERN
WHERE
  GID = /*:Gid*/'GID'
  AND INSERT_ID = /*:Uid*/'nakayama'
  AND VERSION > 0
ORDER BY
  PREFERENCE DESC, ID
