我有一个搜索字段,在这种情况下用户搜索“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 行。所以我希望它在第一行。然后我尝试与工会
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%]%'
它工作正常,但随后的行没有按名称排序。如果我添加
按组织名称订购
到最后一个查询,第一行丢失了。我还有其他办法吗?