この場合、ユーザーが「RG Transport」を検索する検索フィールドがあります。最初に最も正確な一致が必要です。
生成されたクエリは次のとおりです。
SELECT DISTINCT department.bold_id,
departmentid + ' ' + organization.name + ' - '
+ department.name AS DisplayValue,
organization.name
FROM organization,
department
WHERE organization.bold_id = department.organization
AND Upper(searchkeysname) LIKE '%[[]%RG%]%'
AND Upper(searchkeysname) LIKE '%[[]%TRANSPORT%]%'
ORDER BY organization.name
「RG Transport AB」は78行目にあるので、1行目に入れたいです。次に、ユニオンで試します
SELECT DISTINCT department.bold_id, departmentid + ' ' + organization.name + ' - ' + department.name AS DisplayValue,
organization.name FROM Department, Organization
WHERE organization.bold_id = department.organization
AND Upper(searchkeysname) LIKE '%[[]RG TRANSPORT%]%'
UNION ALL
SELECT DISTINCT department.bold_id,
departmentid + ' ' + organization.name + ' - '
+ department.name AS DisplayValue,
organization.name
FROM organization,
department
WHERE organization.bold_id = department.organization
AND Upper(searchkeysname) LIKE '%[[]%RG%]%'
AND Upper(searchkeysname) LIKE '%[[]%TRANSPORT%]%'
正常に動作しますが、次の行は名前でソートされません。追加すると
ORDER BY 組織名.
最後のクエリまで、最初の行が失われます。私ができる他の方法はありますか?