distinct使用方法 sqlserver中的distinct的具體作用是什么?
sqlserver中的distinct的具體作用是什么?當(dāng)我們使用SQL語句查詢數(shù)據(jù)庫表中的數(shù)據(jù)時(shí),結(jié)果可能包含多條重復(fù)記錄,關(guān)鍵字distinct的功能是合并重復(fù)記錄,只顯示一條相同的記錄。SQL語
sqlserver中的distinct的具體作用是什么?
當(dāng)我們使用SQL語句查詢數(shù)據(jù)庫表中的數(shù)據(jù)時(shí),結(jié)果可能包含多條重復(fù)記錄,關(guān)鍵字distinct的功能是合并重復(fù)記錄,只顯示一條相同的記錄。
SQL語句,distinct的關(guān)鍵字使用?
關(guān)鍵字distinct表示返回一個(gè)唯一且不同的值。在表中,可能包含重復(fù)的值。這不是問題,但有時(shí)您可能只想列出不同的值。選擇distinct表示從查詢結(jié)果中刪除重復(fù)行;distinct表示刪除重復(fù)行。擴(kuò)展數(shù)據(jù):在SQL語句中使用distinct的注意事項(xiàng):如果指定select distinct,order by子句中的項(xiàng)必須出現(xiàn)在選擇列表中,否則將發(fā)生錯(cuò)誤。例如,SQL語句:select distinct company from orders order by company ASC可以正常執(zhí)行。但是,如果SQL語句為:select distinct company from orders order by num ASC無法正確執(zhí)行,ASP中將提示錯(cuò)誤“order by子句與(num)distinct沖突”。SQL語句修改為:select distinct company,Num from orders order by Num ASC可以正常執(zhí)行