mysqlÖÐDISTINCTµÄÓ÷¨
distinct Òªº¦×ÖÓÃÓÚ´Ó mysql ÅÌÎÊЧ¹ûÖÐÈ¥³ýÖظ´ÐУ¬½ö±£´æΨһֵ¡£ÆäÓ÷¨°üÀ¨£ºdistinct column_name£º´ÓÖ¸¶¨ÁÐÖÐÈ¥³ýÖظ´Öµ¡£distinct(column_name1, column_name2, …)£º´Ó¶à¸öÁеÄ×éºÏÖÐÈ¥³ýÖظ´Öµ¡£
DISTINCT ÔÚ MySQL ÖеÄÓ÷¨
ÎÊÌ⣺DISTINCT ÔÚ MySQL ÖеÄ×÷ÓÃÊÇʲô£¿
½â´ð£º
DISTINCT Òªº¦×ÖÓÃÓÚ´ÓÅÌÎÊЧ¹ûÖÐÈ¥³ýÖظ´µÄÐУ¬½ö±£´æΨһֵ¡£
Ïêϸ˵Ã÷£º
DISTINCT ÓÐÒÔÏÂÓ÷¨£º
DISTINCT column_name£º´ÓÖ¸¶¨ÁÐÖÐÈ¥³ýÖظ´Öµ¡£
DISTINCT(column_name1, column_name2, …)£º´Ó¶à¸öÁеÄ×éºÏÖÐÈ¥³ýÖظ´Öµ¡£
×¢ÖØ£º
DISTINCT ÓÃÓÚÑ¡ÔñΨһÐУ¬¶ø²»ÊǹýÂËÖظ´Öµ¡£Öظ´ÖµÈÔÈ»±£´æÓÚЧ¹û¼¯ÖУ¬µ«²»»á±»ÏÔʾ¡£
DISTINCT ¶Ô NULL ÖµÃô¸Ð¡£NULL Öµ±»ÊÓΪΨһֵ¡£
ÔÚʹÓà DISTINCT ʱ£¬ORDER BY ×Ó¾ä»áÓ°ÏìЧ¹ûµÄ˳Ðò¡£
DISTINCT ¿ÉÒÔÓëÆäËû¾ÛºÏº¯Êý£¨Èç SUM¡¢COUNT¡¢AVG£©ÍŽáʹÓá£
ÔÚijЩÇéÐÎÏ£¬Ê¹Óà DISTINCT »á½µµÍÅÌÎÊÐÔÄÜ£¬ÌØÊâÊǹØÓÚ´óÐÍÊý¾Ý¼¯¡£
ʾÀý£º
SELECT DISTINCT name FROM customers;
µÇ¼ºó¸´ÖÆ
Õâ¸öÅÌÎʽ«´Ó “customers” ±íÖÐÑ¡ÔñËùÓÐΨһÃû³Æ¡£
SELECT DISTINCT city, country FROM customers;
µÇ¼ºó¸´ÖÆ
Õâ¸öÅÌÎʽ«´Ó “customers” ±íÖÐÑ¡ÔñΨһ¶¼»áºÍ¹ú¼Ò×éºÏ¡£
ÒÔÉϾÍÊÇmysqlÖÐDISTINCTµÄÓ÷¨µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡