MYSQl left joinÁªºÏ²éѯЧÂÊ·ÖÎö
user±í:
id | name
———
1 | libk
2 | zyfon
3 | daodao
user_action±í:
user_id | action
—————
1 | jump
1 | kick
1 | jump
2 | run
4 | swim
sql:
select id, name, action from user as u
left join user_action a on u.id = a.user_id
result:
id | name | action
——————————–
1 | libk | jump ¢Ù
1 | libk | kick ¢Ú
1 | libk | jump ¢Û
2 | zyfon | run ¢Ü
3 | daodao | null ¢Ý
·ÖÎö£º
×¢Òâµ½user_actionÖл¹ÓÐÒ»¸öuser_id=4, action=swimµÄ¼Í¼£¬µ«ÊÇûÓÐÔÚ½á¹ûÖгöÏÖ£¬
¶øuser±íÖеÄid=3, name=daodaoµÄÓû§ÔÚuser_actionÖÐûÓÐÏàÓ¦µÄ¼Í¼£¬µ«ÊÇÈ´³öÏÖÔÚÁ˽á¹û¼¯ÖÐ
ÒòΪÏÖÔÚÊÇleft join£¬ËùÓеŤ×÷ÒÔleftΪ׼.
½á¹û1£¬2£¬3£¬4¶¼ÊǼÈÔÚ×ó±íÓÖÔÚÓÒ±íµÄ¼Í¼£¬5ÊÇÖ»ÔÚ×ó±í£¬²»ÔÚÓÒ±íµÄ¼Í¼
½áÂÛ£º
ÎÒÃÇ¿ÉÒÔÏëÏóleft join ÊÇÕâÑù¹¤×÷µÄ
´Ó×ó±í¶Á³öÒ»Ìõ£¬Ñ¡³öËùÓÐÓëonÆ¥ÅäµÄÓÒ±í¼Í¼(nÌõ)½øÐÐÁ¬½Ó£¬ÐγÉnÌõ¼Í¼(°üÀ¨Öظ´µÄÐУ¬È磺½á¹û1ºÍ½á¹û3)£¬
Èç¹ûÓÒ±ßûÓÐÓëonÌõ¼þÆ¥ÅäµÄ±í£¬ÄÇÁ¬½ÓµÄ×ֶζ¼ÊÇnull.
È»ºó¼ÌÐø¶ÁÏÂÒ»Ìõ¡£
ÒýÉ꣺
ÎÒÃÇ¿ÉÒÔÓÃÓÒ±íûÓÐonÆ¥ÅäÔòÏÔʾnullµÄ¹æÂÉ, À´ÕÒ³öËùÓÐÔÚ×ó±í£¬²»ÔÚÓÒ±íµÄ¼Í¼£¬ ×¢ÒâÓÃÀ´ÅжϵÄÄÇÁбØÐëÉùÃ÷Ϊnot nullµÄ¡£
È磺
sql:
select id, name, action from user as u
left join user_action a on u.id = a.user_id
where a.user_id is NULL
(×¢Òâ:1.ÁÐֵΪnullÓ¦¸ÃÓÃis null ¶ø²»ÄÜÓÃ=NULL
2.ÕâÀïa.user_id ÁбØÐëÉùÃ÷Ϊ NOT NULL µÄ)
result:
id | name | action
————————–
3 | daodao | NULL
——————————————————————————–
Tips:
1. on a.c1 = b.c1 µÈͬÓÚ using(c1)
2. INNER JOIN ºÍ , (¶ººÅ) ÔÚÓïÒåÉÏÊǵÈͬµÄ
3. µ± MySQL ÔÚ´ÓÒ»¸ö±íÖмìË÷ÐÅϢʱ£¬Äã¿ÉÒÔÌáʾËüÑ¡ÔñÁËÄÄÒ»¸öË÷Òý¡£
Èç¹û EXPLAIN ÏÔʾ MySQL ʹÓÃÁË¿ÉÄܵÄË÷ÒýÁбíÖдíÎóµÄË÷Òý£¬Õâ¸öÌØÐÔ½«ÊǺÜÓÐÓõġ£
ͨ¹ýÖ¸¶¨ USE INDEX (key_list)£¬Äã¿ÉÒÔ¸æËß MySQL ʹÓÿÉÄܵÄË÷ÒýÖÐ×îºÏÊʵÄÒ»¸öË÷ÒýÔÚ±íÖвéÕҼǼÐС£
¿ÉÑ¡µ
Ïà¹ØÎĵµ£º
Ò»¡¢ÔÚ±àÒëʱÓÅ»¯MySQL
Èç¹ûÄã´ÓÔ´´úÂë·Ö·¢°²×°MySQL£¬Òª×¢Ò⣬±àÒë¹ý³Ì¶ÔÒÔºóµÄÄ¿±ê³ÌÐòÐÔÄÜÓÐÖØÒªµÄÓ°Ï죬²»Í¬µÄ±àÒ뷽ʽ¿ÉÄܵõ½ÀàËƵÄÄ¿±êÎļþ£¬µ«ÐÔÄÜ¿ÉÄÜÏà²îºÜ´ó£¬Òò´Ë£¬ÔÚ±àÒë°²×°MySQLÊÊÓ¦×Ðϸ¸ù¾ÝÄãµÄÓ¦ÓÃÀàÐÍÑ¡Ôñ×î¿ÉÄܺõıàÒëÑ¡Ïî¡£ÕâÖÖ¶¨ÖƵÄMySQL¿ÉÒÔΪÄãµÄÓ¦ÓÃÌṩ×î¼ÑÐÔÄÜ¡£
¼¼ÇÉ£ºÑ¡ÓýϺõıà ......
ͨ¹ýMySQLÄÚÖÃÈ«ÎļìË÷ʵÏÖÖÐÎĵÄÏà¹Ø¼ìË÷
¹Ø¼ü×Ö£ºMySQL È«ÎļìË÷ È«ÎÄË÷Òý ÖÐÎÄ·Ö´Ê ¶þÔª·Ö´Ê ÇøλÂë ÏàËƶÈ
×¢£º±¾ÎÄʹÓõÄMySQL°æ±¾Îª£ºMySQL 4.0.x
ÔÚMySQL4ÖУ¬ÊÇÒѾ¿ªÊ¼Ö§³ÖÈ«ÎļìË÷£¨Ë÷Òý£©µÄÁË¡£µ«ÊÇÖ»ÊǶÔÓ¢ÎÄÖ§³ÖÈ«ÎļìË÷¡£
ÓÉÓÚÓ¢ÎÄÔÚÊéдÉϵÄÌØÊâÐÔ£¬Ê¹µÃ·Ö´ÊËã·¨Ïà¶ÔÖÐÎÄÀ´Ëµ£¬¼òµ¥µÃ¶à¡£Ò»°ãÀ´Ëµ£¬ÎÒÃÇ ......
¸ã¶¨MySQLÊý¾Ý¿âÖÐÎÄÄ£ºý¼ìË÷ÎÊÌâ
×÷Õß: bianceng, ¡¡³ö´¦:ITר¼ÒÍøÂÛ̳,¡¡ÔðÈαà¼: ³Â×Óç÷,¡¡
2009-10-28 07:00
¡¡¡¡ÔÚ MySQLÏ£¬ÔÚ½øÐÐÖÐÎÄÄ£ºý¼ìË÷ʱ£¬¾³£»á·µ»ØһЩÓëÖ®²»Ïà¹ØµÄ¼Ç¼£¬Èç²éÕÒ "%a%" ʱ£¬·µ»ØµÄ¿ÉÄÜÓÐÖÐÎÄ×Ö·û£¬È´Ã»ÓÐa×Ö·û´æÔÚ¡£
¡¡¡¡ÔÚ MySQLÏ£¬ÔÚ½øÐÐÖÐÎÄÄ£ºý¼ìË÷ʱ£¬¾³£»á·µ»ØһЩÓë ......
ÒýÓÃhttp://hi.baidu.com/mygf/blog/item/b9f55d60049a2ed58cb10d64.html
2009-10-24 00:23
Ò»£¬»ñÈ¡mysqlÓû§ÏµĽø³Ì×ÜÊý
ps -ef | awk '{print $1}' | grep "mysql" | grep -v "grep" | wc-1
¶þ£¬Ö÷»úÐÔÄÜ״̬
# uptime
[root@ ~]# uptime
13:05:52 up 53 days, 52 min, 1 user, l ......
Ë÷ÒýµÄ´ú¼Û
¡¡¡¡Ò»°ãÀ´Ëµ£¬Èç¹ûMySQLÄܹ»ÕÒµ½·½·¨£¬ÀûÓÃË÷ÒýÀ´¸ü¿ìµØ´¦Àí²éѯ£¬Ëü¾Í»áÕâÑù×ö¡£Õâ
Òâζ×Å£¬¶ÔÓÚ´ó¶àÊýÇé¿ö£¬Èç¹ûÄãûÓжԱí½øÐÐË÷Òý£¬¾Í»áʹÐÔÄÜÊܵ½Ë𺦡£Õâ¾ÍÊÇÎÒËùÃè»æµÄË÷ÒýÓŵãµÄÃÀ¾°¡£µ«ÊÇËüÓÐȱµãÂð£¿Óеģ¬ËüÔÚʱ¼äºÍ¿Õ¼äÉ϶¼Óпª
Ïú¡£ÔÚʵ¼ùÖУ¬Ë÷ÒýµÄÓŵãµÄ¼ÛÖµÒ»°ã»á³¬¹ýÕâЩȱµã£¬µ«ÊÇÄ ......