SQL²éѯÓÅ»¯,×¢ÒâwhereÌõ¼þµÄ˳Ðò
×÷Õß:ÂÞ´ú¾ù ldj_work#126.com תÔØÇë±£³ÖÍêÕûÐÔ
1.²âÊÔ±í
employee
¹ÍÔ±id ²¿ÃÅid н½ð
emp_id dept_id salary
01 01 1050
02 01 2000
ok,ÎÒÃÇÒª²éÕÒ²¿ÃÅ01ÏÂ,н½ð¸ßÓÚ1000µÄ¹ÍÔ±
2.ÔÔò¼°Á½¸öSQLµÄ¶Ô±È
ÔÔò,¶àÊýÊý¾Ý¿â¶¼ÊÇ´Ó ×óµ½ÓÒµÄ˳Ðò´¦ÀíÌõ¼þ,°ÑÄܹýÂ˸ü¶àÊý¾ÝµÄÌõ¼þ·ÅÔÚÇ°Ãæ,¹ýÂËÉÙµÄÌõ¼þ·ÅºóÃæ
SQL1: select * from employee
where salary >1000 --Ìõ¼þ1,¹ýÂ˵ÄÊý¾Ý½ÏÉÙ
and dept_id='01' --Ìõ¼þ2,¹ýÂ˵ÄÊý¾Ý±ÈÌõ¼þ1¶à
ÉÏÃæµÄSQL¾Í²»·ûºÏÎÒÃǵÄÔÔòÁË,Ó¦¸Ã°Ñ¹ýÂËÊý¾Ý¸ü¶àµÄÌõ¼þ·ÅÔÚÇ°Ãæ,Òò´Ë¸ÄΪÏÂÃæÕâÑù¸üºÃ
select * from employee
where dept_id='01' --¹ýÂ˸ü¶àÊý¾ÝµÄÌõ¼þ·ÅÔÚÇ°Ãæ
and salary > 1000
Ïà¹ØÎĵµ£º
UNION Ö¸ÁîµÄÄ¿µÄÊǽ«Á½¸ö SQL Óï¾äµÄ½á¹ûºÏ²¢ÆðÀ´¡£´ÓÕâ¸ö½Ç¶ÈÀ´¿´£¬ UNION ¸ú JOIN ÓÐЩÐíÀàËÆ£¬ÒòΪÕâÁ½¸öÖ¸Á¿ÉÒÔÓɶà¸ö±í¸ñÖÐߢȡ×ÊÁÏ¡£ UNION µÄÒ»¸öÏÞÖÆÊÇÁ½¸ö SQL Óï¾äËù²úÉúµÄÀ¸Î»ÐèÒªÊÇͬÑùµÄ×ÊÁÏÖÖÀà¡£ÁíÍ⣬µ±ÎÒÃÇÓà UNIONÕâ¸öÖ¸Áîʱ£¬ÎÒÃÇÖ»»á¿´µ½²»Í¬µÄ×ÊÁÏÖµ (ÀàËÆ SELECT DISTINCT)¡£ unionÖ»Êǽ«Á½¸ö½á¹ ......
SQL JOIN
SQL join ÓÃÓÚ¸ù¾ÝÁ½¸ö»ò¶à¸ö±íÖеÄÁÐÖ®¼äµÄ¹Øϵ£¬´ÓÕâЩ±íÖвéѯÊý¾Ý¡£
Join ºÍ Key
ÓÐʱΪÁ˵õ½ÍêÕûµÄ½á¹û£¬ÎÒÃÇÐèÒª´ÓÁ½¸ö»ò¸ü¶àµÄ±íÖлñÈ¡½á¹û¡£ÎÒÃǾÍÐèÒªÖ´ÐÐ join¡£
Êý¾Ý¿âÖеıí¿Éͨ¹ý¼ü½«±Ë´ËÁªÏµÆðÀ´¡£Ö÷¼ü£¨Primary Key£©ÊÇÒ»¸öÁУ¬ÔÚÕâ¸öÁÐÖеÄÿһÐеÄÖµ¶¼ÊÇΨһµÄ¡£ÔÚ±íÖУ¬Ã¿¸öÖ÷¼üµÄ ......
×î½üÔÚ×ömysqlµÄÐÔÄÜÓÇ»¯£¬×öµ½¶à±íÁ¬½Ó²éѯ£¬±È½ÏÍ·ÌÛ£¬¿´ÁËһЩjoinµÄ×ÊÁÏ£¬ÖÕÓڸ㶨£¬ÕâÀï·ÖÏí³öÀ´£¡
ÍâÁª½Ó¡£ÍâÁª½Ó¿ÉÒÔÊÇ×óÏòÍâÁª½Ó¡¢ÓÒÏòÍâÁª½Ó»òÍêÕûÍⲿÁª½Ó¡£
ÔÚ from ×Ó¾äÖÐÖ¸¶¨ÍâÁª½Óʱ£¬¿ÉÒÔÓÉÏÂÁм¸×é¹Ø¼ü×ÖÖеÄÒ»×éÖ¸¶¨£º
&n ......
VBͨ¹ýADOÁ¬½ÓSQL ServerÊý¾Ý¿â¿ÉÒÔ·ÖΪÓÐÔ´Êý¾Ý¿âÁ¬½ÓºÍÎÞÔ´Êý¾Ý¿âÁ¬½Ó£¬Çø±ðËüÃÇ¿´ÊÇ·ñʹÓÃÁËDSN£¨Êý¾ÝÔ´Ãû³Æ£©À´¾ö¶¨¡£
1 ÎÞÔ´Êý¾Ý¿âÁ¬½Ó
Æäʵ£¬“ÎÞÔ´Êý¾Ý¿â”Á¬½ÓÒ²²¢²»ÊÇ˵²»ÐèÒªÊý¾ÝÔ´£¬Èç¹ûûÓÐÊý¾ÝÔ´ÔòÁ¬½ÓÊÇÖ½ÉÏ̸±ø£¬Ö»ÊDz»ÐèÒªÅäÖÃODBCÊý¾ÝÔ´£¬ÀûÓÃADO¾Í¿Éͨ¹ý´úÂë½øÐÐÁ¬½Ó¡£
1.1 ADO ......
²éѯËÙ¶ÈÂýµÄÔÒòºÜ¶à£¬³£¼ûÈçϼ¸ÖÖ
1¡¢Ã»ÓÐË÷Òý»òÕßûÓÐÓõ½Ë÷Òý(ÕâÊDzéѯÂý×î³£¼ûµÄÎÊÌ⣬ÊdzÌÐòÉè¼ÆµÄȱÏÝ)
2¡¢I/OÍÌÍÂÁ¿Ð¡£¬ÐγÉÁËÆ¿¾±Ð§Ó¦¡£
3¡¢Ã»Óд´½¨¼ÆËãÁе¼Ö²éѯ²»ÓÅ»¯¡£
4¡¢ÄÚ´æ²»×ã
5¡¢ÍøÂçËÙ¶ÈÂý
6¡¢²éѯ³öµÄÊý¾ÝÁ¿¹ý´ó£¨¿ÉÒÔ²ÉÓöà´Î²éѯ£¬ÆäË ......