码迷,mamicode.com
首页 > 数据库 > 详细

不要让mysql犹豫不决

时间:2016-11-30 14:19:56      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:engine   select   key   sam   mysql   charset   utf8   efault   val   

 1 DROP TABLE IF EXISTS `w1`;
 2 CREATE TABLE `w1` (
 3   `waid` int(11) NOT NULL AUTO_INCREMENT,
 4   `wa1` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL,
 5   `wa2` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL,
 6   PRIMARY KEY (`waid`)
 7 ) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
 8 
 9 -- ----------------------------
10 -- Records of w1
11 -- ----------------------------
12 INSERT INTO `w1` VALUES (1, w1-1, 1);
13 INSERT INTO `w1` VALUES (2, w1-2, 2);
 1 DROP TABLE IF EXISTS `w2`;
 2 CREATE TABLE `w2` (
 3   `wbid` int(11) NOT NULL AUTO_INCREMENT,
 4   `wb1` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL,
 5   `wb2` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL,
 6   PRIMARY KEY (`wbid`)
 7 ) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
 8 
 9 -- ----------------------------
10 -- Records of w2
11 -- ----------------------------
12 INSERT INTO `w2` VALUES (1, w2-1, 2);
13 INSERT INTO `w2` VALUES (2, w2-2, 2);

 

 1 SELECT * FROM w1 LEFT JOIN w2 ON w1.wa2=w2.wb2
 2 SELECT * FROM w1 LEFT JOIN w2 ON w2.wb2=w1.wa2
 3 
 4 SELECT * FROM w2 RIGHT JOIN w1 ON w1.wa2=w2.wb2
 5 SELECT * FROM w2 RIGHT JOIN w1 ON w2.wb2=w1.wa2
 6 
 7 
 8 SELECT * FROM w2 LEFT JOIN w1 ON w1.wa2=w2.wb2
 9 SELECT * FROM w2 LEFT JOIN w1 ON w2.wb2=w1.wa2
10 
11 SELECT * FROM w1 RIGHT JOIN w2 ON w1.wa2=w2.wb2
12 SELECT * FROM w1 RIGHT JOIN w2 ON w2.wb2=w1.wa2
13 
14 
15 SELECT * FROM w1 INNER JOIN w2 ON w1.wa2=w2.wb2
16 SELECT * FROM w1 INNER JOIN w2 ON w2.wb2=w1.wa2
17 SELECT * FROM w1 CROSS JOIN w2 ON w1.wa2=w2.wb2
18 SELECT * FROM w1 CROSS JOIN w2 ON w2.wb2=w1.wa2
19 
20 SELECT * FROM w2 INNER JOIN w1 ON w1.wa2=w2.wb2
21 SELECT * FROM w2 INNER JOIN w1 ON w2.wb2=w1.wa2
22 SELECT * FROM w2 CROSS JOIN w1 ON w1.wa2=w2.wb2
23 SELECT * FROM w2 CROSS JOIN w1 ON w2.wb2=w1.wa2

 

不要让mysql犹豫不决

标签:engine   select   key   sam   mysql   charset   utf8   efault   val   

原文地址:http://www.cnblogs.com/yuanjiangw/p/6117248.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!