ÔÚsqlÖÐÌåÏÖ²¢¼¯µÄÒªº¦×ÖÊÇ
sql ÖÐÌåÏÖ²¢¼¯µÄÒªº¦×ÖÊÇ union¡£union ²Ù×÷·û½«Á½¸ö»ò¶à¸ö±íÖеÄÐкϲ¢µ½Ò»¸öЧ¹û¼¯ÖУ¬½ö±£´æΨһÐС£Ó﷨Ϊ£ºselect column1, column2, … from table1 union select column1, column2, … from table2;¡£ÀýÈ磬Ҫ²éÕÒѧÉúºÍÏÈÉúµÄËùÓÐÐÕÃû£¬ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏÂÅÌÎÊ£ºselect name from students union select name from teachers;¡£
SQLÖÐÌåÏÖ²¢¼¯µÄÒªº¦×Ö£ºUNION
²¢¼¯ÔÚSQLÖÐÊÇÒ»¸ö²Ù×÷·û£¬ÓÃÓÚ½«Á½¸ö»ò¶à¸ö±íÖеÄÐкϲ¢µ½Ò»¸öЧ¹û¼¯ÖУ¬Ö»±£´æΨһÐС£UNIONÒªº¦×ÖÓÃÓÚÖ´Ðд˲Ù×÷¡£
Óï·¨£º
SELECT column1, column2, ... FROM table1 UNION SELECT column1, column2, ... FROM table2;
µÇ¼ºó¸´ÖÆ
ʾÀý£º
¼ÙÉèÓÐÁ½¸ö±í£¬studentsºÍteachers¡£ÎÒÃÇÒªÕÒµ½ËùÓÐѧÉúºÍÏÈÉúµÄÐÕÃû£º
SELECT name FROM students UNION SELECT name FROM teachers;
µÇ¼ºó¸´ÖÆ
Ч¹û½«°üÀ¨Ñ§ÉúºÍÏÈÉúµÄÐÕÃû£¬Ã»ÓÐÖظ´¡£
ÒÔÉϾÍÊÇÔÚsqlÖÐÌåÏÖ²¢¼¯µÄÒªº¦×ÖÊǵÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡
ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£