我正在尝试一次搜索多个表以查找搜索词。我的查询是:
SELECT item.ItemID
FROM Inventory.Item item
JOIN Inventory.Category catR // each item can be in several categories
ON catR.ItemID = item.ItemID
JOIN Category.Category cat
ON cat.CategoryID = catR.CategoryID
JOIN Inventory.Brand bran
ON bran.BrandID = item.BrandID
WHERE
item.Description LIKE '%' + @term + '%'
OR
item.Description LIKE '%' + @term
OR
item.Description LIKE @term + '%'
OR
item.Description = @term
OR
cat.CategoryName LIKE '%' + @term + '%'
//same pattern as item.Description used to search CategoryName
//...
OR
bran.BrandName LIKE '%' + @term + '%'
//same pattern as item.Description used to search BrandName
//...
但结果并不如预期。我在“Casement”类别中有大约 50 件商品,但是当 term == “Casement”时,只有 item.Description 中有“Casement”的商品才会被退回。
难道我做错了什么?我应该以更好的方式做到这一点吗?