sqlÖÐallµÄÓ÷¨
allÔËËã·ûÓÃÓÚ½«¶à¸öÅÌÎÊЧ¹ûµÄËùÓÐÐÐ×éºÏ£¬ÓëdistinctÏà·´ºóÕß½ö·µ»ØΨһÐС£ËüÓÃÓÚ·µ»ØËùÓÐÐУ¬ºöÂÔÖظ´£¬²¢´¦ÀínullÖµ¡£ÓëdistinctµÄÇø±ðÔÚÓÚall»á·µ»ØËùÓÐÐУ¬°üÀ¨Öظ´ÐУ¬¶ødistinct½ö·µ»ØΨһÐС£
SQL ÖÐ ALL ÔËËã·ûµÄÓ÷¨
¼ò½é
ALL ÔËËã·ûÔÚ SQL ÖÐÓÃÓÚ½«¶à¸öÅÌÎÊЧ¹ûÖеÄËùÓÐÐÐ×éºÏÔÚÒ»Æð¡£ËüÓë DISTINCT ÔËËã·ûÏà·´£¬ºóÕß½ö·µ»ØΨһÐС£
Óï·¨
SELECT column_list FROM table1 [INNER | LEFT | RIGHT | FULL] JOIN table2 ON join_condition ALL
µÇ¼ºó¸´ÖÆ
Ó÷¨
ALL ÔËËã·ûÓÃÓÚÒÔϳ¡¾°£º
·µ»ØËùÓÐÐУºµ±ÐèÒªºÏ²¢¶à¸öÅÌÎÊЧ¹ûÖеÄËùÓÐÐÐʱ£¬ALL ¿ÉÒÔÈ·±£²»»áÑïÆúÈκÎÐС£
ºöÂÔÖظ´£ºÓë DISTINCT ²î±ð£¬ALL »á·µ»Ø¶à¸öÅÌÎÊЧ¹ûÖеÄËùÓÐÐУ¬×ÝÈ»ËüÃÇÊÇÖظ´µÄ¡£
Óë NULL Öµ´¦Àí£ºALL ÔËËã·û½« NULL ÖµÊÓΪÆäËûÈκÎÖµ£¬ÕâÒâζ×Å×ÝȻһ¸öÅÌÎÊЧ¹ûÖб£´æ NULL Öµ£¬ALL ÈԻ᷵»Ø¸ÃÐС£
Àý×Ó
ÒÔÏÂʾÀýÑÝʾÔõÑùʹÓà ALL ÔËËã·û£º
SELECT * FROM customers ALL SELECT * FROM orders;
µÇ¼ºó¸´ÖÆ
´ËÅÌÎʽ«·µ»Ø¿Í»§±íºÍ¶©µ¥±íÖеÄËùÓÐÐУ¬°üÀ¨Öظ´ÐС£
Óë DISTINCT µÄÇø±ð
DISTINCT ÔËËã·û½ö·µ»ØΨһÐУ¬¶ø ALL ÔËËã·û»á·µ»ØËùÓÐÐУ¬°üÀ¨Öظ´ÐС£ÒÔÏÂʾÀý˵Ã÷ÎúËüÃÇÖ®¼äµÄÇø±ð£º
SELECT DISTINCT customer_id FROM customers; SELECT customer_id FROM customers ALL SELECT customer_id FROM orders;
µÇ¼ºó¸´ÖÆ
µÚÒ»¸öÅÌÎÊÖ»·µ»Ø¿Í»§±íÖÐΨһ¿Í»§ ID£¬¶øµÚ¶þ¸öÅÌÎʻ᷵»ØËùÓпͻ§ ID£¬°üÀ¨Öظ´µÄ¿Í»§ ID¡£
×¢ÖØÊÂÏî
ALL ÔËËã·û¿ÉÄܻᵼÖ´óµÄЧ¹û¼¯£¬ÌØÊâÊǵ±ÅÌÎÊÉæ¼°´ó±íʱ¡£
ÔÚʹÓà ALL ÔËËã·ûʱ£¬±ØÐèÈ·±£ÅþÁ¬Ìõ¼þ׼ȷ£¬ÒÔ×èÖ¹²»ÐëÒªµÄµÑ¿¨¶û»ý¡£
ÒÔÉϾÍÊÇsqlÖÐallµÄÓ÷¨µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡