SQL JOINÖ®ÍêÈ«Ó÷¨
×î½üÔÚ×ömysqlµÄÐÔÄÜÓÇ»¯£¬×öµ½¶à±íÁ¬½Ó²éѯ£¬±È½ÏÍ·ÌÛ£¬¿´ÁËһЩjoinµÄ×ÊÁÏ£¬ÖÕÓڸ㶨£¬ÕâÀï·ÖÏí³öÀ´£¡
ÍâÁª½Ó¡£ÍâÁª½Ó¿ÉÒÔÊÇ×óÏòÍâÁª½Ó¡¢ÓÒÏòÍâÁª½Ó»òÍêÕûÍⲿÁª½Ó¡£
ÔÚ from ×Ó¾äÖÐÖ¸¶¨ÍâÁª½Óʱ£¬¿ÉÒÔÓÉÏÂÁм¸×é¹Ø¼ü×ÖÖеÄÒ»×éÖ¸¶¨£º
LEFT JOIN »ò LEFT OUTER JOIN¡£
×óÏòÍâÁª½ÓµÄ½á¹û¼¯°üÀ¨ LEFT OUTER ×Ó¾äÖÐÖ¸¶¨µÄ×ó±íµÄËùÓÐÐУ¬¶ø²»½ö½ö
ÊÇÁª½ÓÁÐËùÆ¥ÅäµÄÐС£Èç¹û×ó±íµÄijÐÐÔÚÓÒ±íÖÐûÓÐÆ¥ÅäÐУ¬ÔòÔÚÏà¹ØÁªµÄ½á¹û¼¯ÐÐÖÐ
ÓÒ±íµÄËùÓÐÑ¡ÔñÁбíÁоùΪ¿ÕÖµ¡£
RIGHT JOIN »ò RIGHT OUTER JOIN¡£
ÓÒÏòÍâÁª½ÓÊÇ×óÏòÍâÁª½ÓµÄ·´ÏòÁª½Ó¡£½«·µ»ØÓÒ±íµÄËùÓÐÐС£Èç¹ûÓÒ±íµÄijÐÐÔÚ×ó±í
ÖÐûÓÐÆ¥ÅäÐУ¬Ôò½«Îª×ó±í·µ»Ø¿ÕÖµ¡£
FULL JOIN »ò FULL OUTER JOIN¡£
ÍêÕûÍⲿÁª½Ó·µ»Ø×ó±íºÍÓÒ±íÖеÄËùÓÐÐС£µ±Ä³ÐÐÔÚÁíÒ»¸ö±íÖÐûÓÐÆ¥ÅäÐÐʱ£¬ÔòÁí
Ò»¸ö±íµÄÑ¡ÔñÁбíÁаüº¬¿ÕÖµ¡£Èç¹û±íÖ®¼äÓÐÆ¥ÅäÐУ¬ÔòÕû¸ö½á¹û¼¯Ðаüº¬»ù±íµÄÊý¾Ý
Öµ¡£
½öµ±ÖÁÉÙÓÐÒ»¸öͬÊôÓÚÁ½±íµÄÐзûºÏÁª½ÓÌõ¼þʱ£¬ÄÚÁª½Ó²Å·µ»ØÐС£ÄÚÁª½ÓÏû³ýÓëÁí
Ò»¸ö±íÖеÄÈκÎÐв»Æ¥ÅäµÄÐС£¶øÍâÁª½Ó»á·µ»Ø from ×Ó¾äÖÐÌáµ½µÄÖÁÉÙÒ»¸ö±í»ò
ÊÓͼµÄËùÓÐÐУ¬Ö»ÒªÕâЩÐзûºÏÈκΠWHERE »ò HAVING ËÑË÷Ìõ¼þ¡£½«¼ìË÷ͨ
¹ý×óÏòÍâÁª½ÓÒýÓõÄ×ó±íµÄËùÓÐÐУ¬ÒÔ¼°Í¨¹ýÓÒÏòÍâÁª½ÓÒýÓõÄÓÒ±íµÄËùÓÐÐС£ÍêÕûÍâ
²¿Áª½ÓÖÐÁ½¸ö±íµÄËùÓÐÐж¼½«·µ»Ø¡£
Microsoft® SQL Server™ 2000 ¶ÔÔÚ from ×Ó¾äÖÐÖ¸¶¨µÄÍâ
Áª½ÓʹÓÃÒÔÏ SQL-92 ¹Ø¼ü×Ö£º
Ïà¹ØÎĵµ£º
ÔÎijö´¦£ºhttp://blog.csdn.net/zk911/archive/2005/11/23/535432.aspx
×÷Õߣºzk911
¿´ÍêÕâƪÎÄÕµĵÚÒ»¸Ð¾õÊÇ£¬ËäÈ»¶ÔÓÚÈÕÆÚÀàÐÍÊý¾ÝʹÓõúÜËã˳Àû£¬²»¹ý×÷Õß Ìáµ½µÄһЩ¶«Î÷»¹Õæ²»ÖªµÀ¡£ÓÐʱºòÔÚÓ¦ÓÃÉÏ£¬²»¾õµÃ±ÈÀÏÍâ²îµ½ÄÇÀïÈ¥¡£µ«ÊÇ£¬ ÀÏÍâµÄÒ»¸öÓÅÁ¼Ï°¹ßϸ¿Û¸ÅÄî²¢½øÐÐʵ֤¼ìÑ飻¶øÎÒÃǵÄÏ°¹ßÊǸÅÄîÊǸÅÄӦÓÃ Ê ......
SQLÃæÊÔÌ⣨1£©
create table testtable1
(
id int IDENTITY,
department varchar(12)
)
select * from testtable1
insert into testtable1 values('Éè¼Æ')
insert into testtable1 values('Êг¡')
insert into testtable1 values('ÊÛºó')
/*
½á¹û
id department
1 Éè¼Æ
2 Êг¡
......
´æ´¢¹ý³Ì
Óŵ㣺
1.ÓÉÓÚÓ¦ÓóÌÐòËæ×Åʱ¼äÍÆÒƻ᲻¶Ï¸ü¸Ä£¬Ôöɾ¹¦ÄÜ£¬T£SQL¹ý³Ì´úÂë»á±äµÃ¸ü¸´ÔÓ£¬StoredProcedureΪ·â×°´Ë´úÂëÌṩÁËÒ»¸öÌ滻λÖá£
2.Ö´Ðмƻ®£¨´æ´¢¹ý³ÌÔÚÊ×´ÎÔËÐÐʱ½«±»±àÒ룬Õ⽫²úÉúÒ»¸öÖ´Ðмƻ®££ ʵ¼ÊÉÏÊÇ Microsoft SQL ServerΪÔÚ´æ´¢¹ý³ÌÖлñÈ¡ÓÉ T-SQL Ö¸¶¨µÄ½á¹û¶ø±ØÐë²ÉÈ¡µÄ²½ÖèµÄ¼Ç¼ ......
1¡¢Ã»ÓÐË÷Òý»òÕßûÓÐÓõ½Ë÷Òý(ÕâÊDzéѯÂý×î³£¼ûµÄÎÊÌ⣬ÊdzÌÐòÉè¼ÆµÄȱÏÝ)
¡¡¡¡2¡¢I/OÍÌÍÂÁ¿Ð¡£¬ÐγÉÁËÆ¿¾±Ð§Ó¦¡£
¡¡¡¡3¡¢Ã»Óд´½¨¼ÆËãÁе¼Ö²éѯ²»ÓÅ»¯¡£
¡¡¡¡4¡¢ÄÚ´æ²»×ã
¡¡¡¡5¡¢ÍøÂçËÙ¶ÈÂý
¡¡¡¡6¡¢²éѯ³öµÄÊý¾ÝÁ¿¹ý´ó(¿ÉÒÔ²ÉÓöà´Î²éѯ£¬ÆäËûµÄ·½·¨½µµÍÊý¾ÝÁ¿)
¡¡¡¡7¡¢Ëø»òÕßËÀËø(ÕâÒ²ÊDzéѯÂý×î³£¼ûµÄÎÊÌ⣠......
CHARINDEXº¯Êý·µ»Ø×Ö·û»òÕß×Ö·û´®ÔÚÁíÒ»¸ö×Ö·û´®ÖеÄÆðʼλÖá£CHARINDEXº¯Êýµ÷Ó÷½·¨ÈçÏ£º
CHARINDEX ( expression1 , expression2 [ , start_location ] )
Expression1ÊÇÒªµ½expression2ÖÐÑ°ÕÒµÄ×Ö·ûÖУ¬start_locationÊÇCHAR ......