distinct关键字

对于distinct关键字,distinct关键字应用于所有列而不仅是前置它的列,如果给出多个列,将会比较两个列。

 这是完整表,

首先是select distinct username from user;  看看结果

 可以看到已经去重了,

现在是select distinct username,sex from user; 看看结果

 可以看到这个去重是先比较username,如果相同再比较sex,如果都相同就去重,不然不会去重。

猜你喜欢

转载自www.cnblogs.com/cold-windy/p/11785211.html