oracleÆ´½ÓÅÌÎÊÓï¾ä
Æ´½ÓÅÌÎÊÓï¾äÊÇÒ»ÖÖ½«¶à¸öÅÌÎÊ×éºÏÔÚÒ»ÆðÐγÉÒ»¸öÖØ´óÅÌÎʵÄÓï¾ä¡£Æ´½ÓÅÌÎÊ¿ÉÒÔͨ¹ý union ²Ù×÷·û£¨ºÏ²¢Í¬½á¹¹Êý¾Ý£©»òÅþÁ¬²Ù×÷·û£¨ºÏ²¢Ïà¹ØÊý¾Ý£©ÊµÏÖ£¬ÀýÈ磺 select from table1 union select from table2; select * from table1 inner join table2 on table1.id = table2.id;¡£
OracleÆ´½ÓÅÌÎÊÓï¾ä
ʲôÊÇÆ´½ÓÅÌÎÊÓï¾ä£¿
Æ´½ÓÅÌÎÊÓï¾äÊǽ«¶à¸ö×ÔÁ¦µÄÅÌÎÊÓï¾ä×éºÏÔÚÒ»ÆðÐγÉÒ»¸ö¸üÖØ´óµÄÅÌÎÊÓï¾ä£¬´Ó¶øÒ»´ÎÐÔ»ñÈ¡ËùÐèµÄÊý¾Ý¡£
ÔõÑùÆ´½ÓÅÌÎÊÓï¾ä£¿
ÓÐÁ½ÖÖÖ÷ÒªµÄÒªÁì¿ÉÒÔÆ´½ÓÅÌÎÊÓï¾ä£º
UNION ²Ù×÷·û£ºÓÃÓںϲ¢À´×Ô¶à¸öÅÌÎʵÄÏàͬ½á¹¹µÄÊý¾Ý¡£
INNER JOIN¡¢LEFT JOIN¡¢RIGHT JOIN ºÍ FULL JOIN ²Ù×÷·û£ºÓÃÓںϲ¢À´×Ô¶à¸ö±íµÄÏà¹ØÊý¾Ý¡£
ʹÓà UNION ²Ù×÷·ûÆ´½ÓÅÌÎÊÓï¾ä
SELECT * FROM table1 UNION SELECT * FROM table2;
µÇ¼ºó¸´ÖÆ
ʹÓÃÅþÁ¬²Ù×÷·ûÆ´½ÓÅÌÎÊÓï¾ä
SELECT * FROM table1 INNER JOIN table2 ON table1.id = table2.id;
µÇ¼ºó¸´ÖÆ
ʾÀý
¼ÙÉèÎÒÃÇÓÐÁ½¸ö±í£¬customers ºÍ orders£¬ËüÃÇͨ¹ý customer_id ÁÐÏà¹Ø¡£Òª»ñÈ¡ËùÓпͻ§¼°Æ䶩µ¥£¬ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏÂÆ´½ÓÅÌÎÊÓï¾ä£º
SELECT * FROM customers INNER JOIN orders ON customers.customer_id = orders.customer_id;
µÇ¼ºó¸´ÖÆ
×¢ÖØÊÂÏî
UNION ²Ù×÷·ûÖ»Äܺϲ¢¾ßÓÐÏàͬ½á¹¹£¨ÁÐÊýºÍÊý¾ÝÀàÐÍ£©µÄÊý¾Ý¡£
UNION ²Ù×÷·û»áɾ³ýÖظ´ÐУ¬¶øÅþÁ¬²Ù×÷·û»á±£´æÖظ´ÐС£
¿ÉÒÔʹÓÃǶÌ×ÅÌÎÊÀ´½¨Éè¸üÖØ´óµÄ¶à±íÆ´½ÓÅÌÎÊÓï¾ä¡£
ÒÔÉϾÍÊÇoracleÆ´½ÓÅÌÎÊÓï¾äµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡