ʵÀý½²½âMySQLÁªºÏ²éѯ
ÔÚ½²MySQLµÄJoinÓ﷨ǰ»¹ÊÇÏȻعËÒ»ÏÂÁª½áµÄÓï·¨£¬ºÇºÇ£¬ÆäʵÁ¬ÎÒ×Ô¼º¶¼ÍüµÃ²î²»¶àÁË£¬ÄǾʹó¼ÒÒ»ÆðÎÂÏ°°É£¨Èç¹ûÄÚÈÝÓдíÎó»òÓÐÒÉÎÊ£¬¹úÄÚ¹ØÓÚMySQLÁª½á²éѯµÄ×ÊÁÏÊ®·ÖÉÙ£¬ÏàÐÅ´ó¼ÒÔÚ¿´Á˱¾Îĺó»á¶ÔMySQLÁª½áÓï·¨ÓÐÏ൱ÇåÎúµÄÁ˽⣬Ҳ²»»á±»OracleµÄÍâÁª½áµÄ£¨“£«”ºÅ£©ÅªµÃºýÍ¿ÁË¡£
ÔÚSQL±ê×¼Öй滮µÄ£¨Join£©Áª½á´óÖ·ÖΪÏÂÃæËÄÖÖ£º
1£® ÄÚÁª½á£º½«Á½¸ö±íÖдæÔÚÁª½á¹ØϵµÄ×ֶηûºÏÁª½á¹ØϵµÄÄÇЩ¼Ç¼ÐγɼǼ¼¯µÄÁª½á¡£
2£® ÍâÁª½á£º·ÖΪÍâ×óÁª½áºÍÍâÓÒÁª½á¡£
×óÁª½áA¡¢B±íµÄÒâ˼¾ÍÊǽ«±íAÖеÄÈ«²¿¼Ç¼ºÍ±íBÖÐÁª½áµÄ×Ö¶ÎÓë±íAµÄÁª½á×ֶηûºÏÁª½áÌõ¼þµÄÄÇЩ¼Ç¼ÐγɵļǼ¼¯µÄÁª½á£¬ÕâÀï×¢ÒâµÄÊÇ×îºó³öÀ´µÄ¼Ç¼¼¯»á°üÀ¨±íAµÄÈ«²¿¼Ç¼¡£
ÓÒÁª½áA¡¢B±íµÄ½á¹ûºÍ×óÁª½áB¡¢AµÄ½á¹ûÊÇÒ»ÑùµÄ£¬Ò²¾ÍÊÇ˵£º
Select A.name B.name from A Left Join B On A.id=B.id
ºÍSelect A.name B.name from B Right Join A on B.id=A.idÖ´ÐкóµÄ½á¹ûÊÇÒ»ÑùµÄ¡£
3£®È«Áª½á£º½«Á½¸ö±íÖдæÔÚÁª½á¹ØϵµÄ×ֶεÄËùÓмǼȡ³öÐγɼǼ¼¯µÄÁª½á£¨Õâ¸ö²»ÐèÒª¼ÇÒ䣬ֻҪÊDzéѯÖÐÌáµ½Á˵ıíµÄ×ֶζ¼»áÈ¡³ö£¬ÎÞÂÛÊÇ·ñ·ûºÏÁª½áÌõ¼þ£¬Òò´ËÒâÒå²»´ó£©¡£
ʵÀý½²½âMySQLÁªºÏ²éѯ.ÄÇÏÂÃæ¾Í¾ßÌå½²½²¼òµ¥µÄJOINµÄÓ÷¨ÁË¡£Ê×ÏÈÎÒÃǼÙÉèÓÐ2¸ö±íAºÍB£¬ËûÃǵıí½á¹¹ºÍ×ֶηֱðΪ£º
±íA£º
ID
Name
1
Tim
2
Jimmy
3
John
4
Tom
±íB£º
ID
Hobby
1
Football
2
Basketball
2
Tennis
4
Soccer
1£® ÄÚÁª½á£º
Select A.Name B.Hobby from A, B where A.id = B.id£¬ÕâÊÇÒþʽµÄÄÚÁª½á£¬²éѯµÄ½á¹ûÊÇ£º
Name
Hobby
Tim
Football
Jimmy
Basketball
Jimmy
Tennis
Tom
Soccer
ËüµÄ×÷ÓÃºÍ Select A.Name from A INNER JOIN B ON A.id = B.idÊÇÒ»ÑùµÄ¡£ÕâÀïµÄINNER JOIN»»³ÉCROSS JOINÒ²ÊÇ¿ÉÒԵġ£
2£® Íâ×óÁª½á
Select A.Name from A Left JOIN B ON A.id = B.id£¬µäÐ͵ÄÍâ×óÁª½á£¬ÕâÑù²éѯµÃµ½µÄ½á¹û½«»áÊDZ£ÁôËùÓÐA±íÖÐÁª½á×ֶεļǼ£¬ÈôÎÞÓëÆäÏà¶ÔÓ¦µÄB±íÖеÄ×ֶμǼÔòÁô¿Õ£¬½á¹ûÈçÏ£º
Name
Hobby
Tim
Football
Jimmy
Basketball£¬Tennis
John
Tom
Soccer
ËùÒÔ´ÓÉÏÃæ½á¹û¿´³ö£¬ÒòΪA±íÖеÄJohn¼Ç¼µÄIDûÓÐÔÚB±íÖÐÓжÔÓ¦ID£¬Òò´ËΪ¿Õ£¬µ«NameÀ¸ÈÔÓÐJohn¼Ç¼¡£
3£® ÍâÓÒÁª½á
Èç¹û°ÑÉÏÃæ²éѯ¸Ä³ÉÍâÓÒÁª½á£ºSelect A.Name from A Right JOIN B ON A.id = B.id£¬Ôò½á¹û½«»áÊÇ£º
Name
Hobby
Tim
Footb
Ïà¹ØÎĵµ£º
¸ã¶¨MySQLÊý¾Ý¿âÖÐÎÄÄ£ºý¼ìË÷ÎÊÌâ
×÷Õß: bianceng, ¡¡³ö´¦:ITר¼ÒÍøÂÛ̳,¡¡ÔðÈαà¼: ³Â×Óç÷,¡¡
2009-10-28 07:00
¡¡¡¡ÔÚ MySQLÏ£¬ÔÚ½øÐÐÖÐÎÄÄ£ºý¼ìË÷ʱ£¬¾³£»á·µ»ØһЩÓëÖ®²»Ïà¹ØµÄ¼Ç¼£¬Èç²éÕÒ "%a%" ʱ£¬·µ»ØµÄ¿ÉÄÜÓÐÖÐÎÄ×Ö·û£¬È´Ã»ÓÐa×Ö·û´æÔÚ¡£
¡¡¡¡ÔÚ MySQLÏ£¬ÔÚ½øÐÐÖÐÎÄÄ£ºý¼ìË÷ʱ£¬¾³£»á·µ»ØһЩÓë ......
Ë÷ÒýÊÇÌá¸ß²éѯËٶȵÄ×îÖØÒªµÄ¹¤¾ß¡£µ±È»»¹ÓÐÆäËüµÄһЩ¼¼Êõ¿É¹©Ê¹Ó㬵«ÊÇÒ»°ãÀ´ËµÒýÆð×î´óÐÔÄܲîÒìµÄ¶¼ÊÇË÷ÒýµÄÕýȷʹÓá£ÔÚMySQLÓʼþÁбíÖУ¬ÈËÃÇ
¾³£Ñ¯ÎÊÄÇЩÈòéѯÔËÐеøü¿ìµÄ·½·¨¡£ÔÚ´ó¶àÊýÇé¿öÏ£¬ÎÒÃÇÓ¦¸Ã»³ÒÉÊý¾Ý±íÉÏÓÐûÓÐË÷Òý£¬²¢ÇÒͨ³£ÔÚÌí¼ÓË÷ÒýÖ®ºóÁ¢¼´½â¾öÁËÎÊÌâ¡£µ±È»£¬²¢²»×ÜÊÇÕâÑù¼òµ¥
¾Í¿ÉÒÔ½ ......
---- ÔÚÊý¾Ý¿âµÄÓ¦Óÿª·¢ÖУ¬³£³£»áÓöµ½ÐÔÄܺʹú¼ÛµÄÖ®¼äì¶Ü¡£ÒÔ×÷ÕßÔÚ¿ª·¢¹ÉÊÐÐÐ
Çé²éѯºÍ½»Ò×ϵͳÖÐÓöµ½µÄÎÊÌâΪÀý£¬ÒªÔÚʵʱ¼Ç¼1000¶àÖ»¹ÉƱÿ·ÖÖÓ¸üÐÂÒ»´ÎµÄÐÐ
ÇéÊý¾ÝµÄͬʱ£¬ÏìÓ¦´óÁ¿²¢·¢Óû§µÄÊý¾Ý²éѯÇëÇ󡣿¼Âǵ½ÐԼ۱ȺÍÒ×ά»¤ÐÔ£¬ÏµÍ³ÓÖ
ÒªÇóÔÚ»ùÓÚPC·þÎñÆ÷£¬Windows NTƽ̨µÄÈíÓ²¼þ»·¾³ÏÂʵÏÖ¡£¿ª ......
mysqldump -u[user] -p[password] [databasename] > [dump_name]
ÔÚ½« dump_name Õâ¸öµµ°¸¸´ÖƵ½Áíһ̨¼ÆËã»úÉÏ
Áíһ̨¼ÆËã»úÉÏÏȽøÈëmysql
½¨Á¢Ò»¸ö database ÔÙÖ´ÐÐÏÂÁÐÖ¸Áî
mysql -u[user] -p[password] [database_name] < [dump_name]
MYSQL¼¸ÖÖ±¸·Ý·½·¨¸ÅÊö
MysqlÊý¾Ý
¿â±¸·ÝÖ÷ÒªÓÐ4Ö ......