mysql²Ù×÷ Left join , Right Join, Inner Join
Ò».ÏÈ¿´Ò»Ð©×î¼òµ¥µÄÀý×Ó
Àý×Ó
Table A
aid adate
1 a1
2 a2
3 a3
TableB
bid bdate
1 b1
2 b2
4 b4
Á½¸ö±ía,bÏàÁ¬½Ó,Ҫȡ³öidÏàͬµÄ×Ö¶Î
select * from a inner join
b on a.aid = b.bidÕâÊǽöÈ¡³öÆ¥ÅäµÄÊý¾Ý.
´ËʱµÄÈ¡³öµÄÊÇ:
1 a1 b1
2 a2 b2
ÄÇôleft join Ö¸:
select * from a left join
b on
a.aid = b.bid
È¡³öa±íËùÓÐÊý¾Ý,ÄÃbµÄÊý¾ÝÓëa±È½Ï,ÏàͬµÄÈ¡³ö,²»Í¬µÄbÈ¡¿Õֵȡ³ö
´ËʱµÄÈ¡³öµÄÊÇ:
1 a1 b1
2 a2 b2
3 a3 ¿Õ×Ö·û
ͬÑùµÄÒ²ÓÐright join
select * from a right join
b on
a.aid = b.bid
È¡³öb±íËùÓÐÊý¾Ý,ÄÃaµÄÊý¾ÝÓëb±È½Ï,ÏàͬµÄÈ¡³ö,²»Í¬µÄaÈ¡¿Õֵȡ³ö
´ËʱµÄÈ¡³öµÄÊÇ:
1 a1 b1
2 a2 b2
4 ¿Õ×Ö·û b4
×¢:
¶¼ÊÇÔÚonµÄÌõ¼þÏÂ
¶þ. left join/right join/inner join²Ù×÷ÑÝʾ
±í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Óï¾äÈçÏÂ:
SELECT
*
from
A
LEFT
JOIN
B
ON
A.aID
=
B.bID
½á¹ûÈçÏÂ:
aID aNum &
Ïà¹ØÎĵµ£º
²éѯÊÇÊý¾Ý¿â¼¼ÊõÖÐ×î³£ÓõIJÙ×÷¡£²éѯ²Ù×÷µÄ¹ý³Ì±È½Ï¼òµ¥£¬Ê×ÏÈ´Ó¿Í»§¶Ë·¢³ö²éѯµÄSQLÓï¾ä£¬Êý¾Ý¿â·þÎñ¶ËÔÚ½ÓÊÕµ½Óɿͻ§¶Ë·¢À´µÄSQLÓï¾äºó£¬Ö´ÐÐÕâÌõSQLÓï¾ä£¬È»ºó½«²éѯµ½µÄ½á¹û·µ»Ø¸ø¿Í»§¶Ë¡£ËäÈ»¹ý³ÌºÜ¼òµ¥£¬µ«²»Í¬µÄ²éѯ·½Ê½ºÍÊý¾Ý¿âÉèÖ㬶ԲéѯµÄÐÔÄܽ«»áÓкÜÔÚµÄÓ°Ïì¡£
Òò´Ë£¬±¾ÎľÍÔÚMySQLÖг£ÓõIJéѯÓÅ»¯¼¼Êõ½ø ......
·µ»ØÒ»¸ö½á¹ûÈ«ÊÀ½ç¶¼ÖªµÀÔõô´¦Àí£¬¹Ø¼üÊÇ·µ»Ø¶à¸ö½á¹û¼¯¾Í²»ºÃ°ìÁË£¬ÏÂÃæÓÐÒ»½â¾ö°ì·¨
´æ´¢¹ý³Ì´úÂë
DELIMITER $$;
DROP PROCEDURE IF EXISTS `test`.`sp_test`$$
CREATE PROCEDURE `test`.`sp_test` ()
BEGIN
select * from `user`.`user` limit 0, 50;
select coun ......
ÕâÀ½éÉÜÒ»ÏÂCentOSÏÂMySQLÊý¾Ý¿â·þÎñÆ÷µÄ¹¹½¨·½·¨¡£
°²×°MySQL¼°Ïà¹Ø×é¼þ
¡¡¡¡Ê×ÏÈ£¬°²×°MySQL¡£
[root@sample ~]#
yum
-y install mysql-server
¡¡ ← °²×°MySQL
Setting up Install Process
Setting up repositories
dag 100% |=========================| 1.1 kB 00:00
update ......
Ê×ÏÈ·ÅÖúÃjdbcÇý¶¯³ÌÐò£¬ÔÚ java\jre6\lib\ext\Ï£¬java\jdk1.6\jre\libµÈµØ·½¶¼·ÅÆðÀ´£¬ÒòΪ²»È·¶¨ÔÚÄÄÀïÓÐÓ÷··
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost/DATABASENAME?user=USERNAME&password=PASSWORD&useUnicode=tru ......
ÓÉÓÚ×î½üÒ»Ö±ÔÚÁ˽âmysql¡£¸÷ÖÖ±íÀàÐ͵ÄÊý¾Ý´æ´¢ÒÔ¼°Ïà¹ØÏÞÖÆ¾ÍÊDZØÐëÁ˽âµÄ·½ÃæÁË¡£
×Ô¼ºµÄ·þÎñÆ÷»·¾³£ºOS Cent OS ext3£¬memory 4G£¬ disk 2T block size 4K¡£
¾µ÷²é£¬linuxÏÂÎļþ×î´óÊÇ´æÔÚÏÞÖÆµÄ¡£È¥googleÉÏËÑÁËËÑ£¬´ó¼Ò˵·¨²»Ò»£¬×îÖÕ×Ô¼º»¹ÊÇÕÒµ½±È½Ï¹Ù·½µÄ˵¡£Ïê¼ûhttp://en.wikipedia.org/wiki/Ext3 ËùÒÔ× ......