對於搜索功能,我想返回三種類型的結果,所以我查詢了三次。或許,這將是更好的JOIN或UNION查詢到一個,但如何..如何結合同一表中的三個「select distinct」
string sql1 = "SELECT DISTINCT area, CHARINDEX(@ss, area) FROM rgmaplocation WHERE area LIKE '%' + @ss + '%' ORDER BY CHARINDEX(@ss, area) ";
string sql2 = "SELECT DISTINCT compound, CHARINDEX(@ss, compound) FROM rgmaplocation WHERE compound LIKE '%' + @ss + '%' ORDER BY CHARINDEX(@ss, compound) ";
string sql3 = "SELECT DISTINCT streetname, CHARINDEX(@ss, streetname) FROM rgmaplocation WHERE streetname LIKE '%' + @ss + '%' ORDER BY CHARINDEX(@ss, streetname)";
這是完美的工作。謝謝 :) – Jesper