SQLÖÐJOINµÄʹÓÃ
(×¢:outerµÄÒâ˼¾ÍÊÇ"ûÓйØÁªÉϵÄÐÐ"¡£)
1.cross join È«ÍâÁ¬½Ó(µÑ¿¨¶û³Ë»ý)
SELECT A.*, B.* from A FULL OUTER JOIN B ON A.ID = B.ID
2.inner join ÄÚÁ¬½Ó(Ôڵѿ¨¶û³Ë»ýµÄ½á¹û¼¯ÖÐÈ¥µô²»·ûºÏÁ¬½ÓÌõ¼þµÄÐÐ)
SELECT A.* from A INNER JOIN B ON A.ID=B.ID
3.left outer join ×óÍâÁ¬½Ó(ÔÚinner joinµÄ½á¹û¼¯ÉϼÓÉÏ×ó±íÖÐû±»Ñ¡ÉϵÄÐУ¬ÐеÄÓÒ±í²¿·Öÿ¸ö×ֶζ¼ÓÃNUllÌî³ä)
SELECT A.* from A LEFT JOIN B ON A.ID = B.ID
4.right outer join ÓÒÍâÁ¬½Ó(ÔÚinner joinµÄ½á¹û¼¯ÉϼÓÉÏÓÒ±íÖÐû±»Ñ¡ÉϵÄÐУ¬ÐеÄ×ó±í²¿·ÖÈ«ÓÃNULLÌî³ä¡£)
SELECT A.* from A RIGHT JOIN B ON A.ID = B.ID
¾ÙÀý˵Ã÷£º
±íA
¼Ç¼ÈçÏ£º
aID aNum
1 a20050111
2 a20050112
3 a20050113
4 a20050114
5 a20050115
±íB
¼Ç¼ÈçÏÂ:
bID bName
1 2006032401
2 2006032402
3 2006032403
4 2006032404
8 2006032408
ʵÑéÈçÏÂ
:
1.left join
sql
Óï
Ïà¹ØÎĵµ£º
µÚ¶þÊ®Ì⣺
ÔõôÑù³éÈ¡Öظ´¼Ç¼
񡜧
id name
--------
1 test1
2 test2
3 test3
4 test4
5 test5
6 test6
2 test2
3 test3
2 test2
6 test6
²é³öËùÓÐÓÐÖظ´¼Ç¼µÄÊý¾Ý£¬ÓÃÒ»¾äsql À´ÊµÏÖ
create table D(
id varchar (20),
name varchar (20)
)
insert into D values('1','test1')
insert into D v ......
7¡¢¶ÔÏóÀàÐͼ̳Ð
¶ÔÏóÀàÐÍʵÏÖÔÊÐíÎÒÃÇ´´½¨Ò»¸ö»ùÀàÐÍ£¬»ò½Ð¸¸ÀàÐÍ£¬ÕâÖÖÀàÐ͵ÄÊôÐÔ»ò·½·¨¿ÉÒÔ±»ÁíÒ»¸ö¶ÔÏóÀàÐͼ̳С£È»ºó¿ÉÒÔ´´½¨Ò»¸ö×ÓÀàÐÍ£¬»ò½Ðº¢×ÓÀàÐÍ£¬Ö±½ÓʹÓü̳йýÀ´µÄÊôÐÔ»ò·½·¨£¬»òÕßÓÃ×Ô¼ºµÄÊôÐԺͷ½·¨ÖØд¸¸ÀàÐ͵ÄÊôÐÔ»ò·½·¨¡£
INSTANTIABLE¹Ø¼ü×Ö±íʾÎÒÃÇ¿ÉÒÔ´Ó¸ÃÀàÐÍÖÐʵÀý»¯»òÕß´´½¨¶ÔÏ ......
Subquery: (single-row subqueries and multi-rows subqueries).
select select_list
from table
where expr operator (select select_list from table);
single-row subqueries operator: =, >, >=, <, <=, <>
e.g.:
1. select department_id, min(salary) from employees group by department_id ......
oracle tips
ExistµÄÓ÷¨£º
select gw.ndocid from
(select ndocid from wf_doc_gw_shouwen union select ndocid from wf_doc_gw_fawen) gw
where
not exists (select null from wf_doc_gw_sn sn where sn.ndocid=gw.ndocid)
2¡£°ÑGW±íºÍSN±íÀïÏàͬµÄNDOCIDÏÔʾ³öÀ´
select gw.ndocid from
(se ......
ÔÚ³ÌÐòµÄ¿ª·¢¹ý³ÌÖУ¬´¦Àí·ÖÒ³ÊÇ´ó¼Ò½Ó´¥±È½ÏƵ·±µÄʼþ£¬ÒòΪÏÖÔÚÈí¼þ»ù±¾É϶¼ÊÇÓëÊý¾Ý¿â½øÐйҵöµÄ¡£µ«Ð§ÂÊÓÖÊÇÎÒÃÇËù×·ÇóµÄ£¬Èç¹ûÊÇÏñÔÀ´ÄÇÑù°ÑËùÓÐÂú×ãÌõ¼þµÄ¼Ç¼ȫ²¿¶¼Ñ¡Ôñ³öÀ´£¬ÔÙÈ¥½øÐзÖÒ³´¦Àí£¬ÄÇô¾Í»á¶à¶àµÄÀ˷ѵôÐí¶àµÄϵͳ´¦Àíʱ¼ä¡£ÎªÁËÄܹ»°ÑЧÂÊÌá¸ß£¬ËùÒÔÏÖÔÚÎÒÃǾÍֻѡÔñÎÒÃÇÐèÒªµÄÊý¾Ý£¬¼õÉÙÊý¾Ý ......