mysql基础
Posted 懒企鹅
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql基础相关的知识,希望对你有一定的参考价值。
左外连,右外连
CREATE DATABASE test_mysql; use test_mysql; CREATE TABLE left_tb( id INT(11) PRIMARY KEY AUTO_INCREMENT,name VARCHAR(32) ); CREATE TABLE right_tb( id INT(11) PRIMARY KEY AUTO_INCREMENT,name VARCHAR(32),age INT(11) ); INSERT INTO left_tb (name) VALUES (‘zhangsan‘); INSERT INTO left_tb (name) VALUES (‘lisi‘); INSERT INTO left_tb (name) VALUES (‘wangwu‘); SELECT * from left_tb; 1 zhangsan 2 lisi 3 wangwu INSERT INTO right_tb (name,age) VALUES (‘aaa‘,11); INSERT INTO right_tb (name,age) VALUES (‘bbb‘,12); INSERT INTO right_tb (name,age) VALUES (‘ccc‘,13); INSERT INTO right_tb (name,age) VALUES (‘ddd‘,14); SELECT * from right_tb; 1 aaa 11 2 bbb 12 3 ccc 13 4 ddd 14
SELECT * from left_tb l LEFT JOIN right_tb r ON l.id=r.id; +----+----------+------+------+------+ | id | name | id | name | age | +----+----------+------+------+------+ | 1 | zhangsan | 1 | aaa | 11 | | 2 | lisi | 2 | bbb | 12 | | 3 | wangwu | 3 | ccc | 13 | +----+----------+------+------+------+ SELECT * from left_tb l RIGHT JOIN right_tb r ON l.id=r.id; +------+----------+----+------+------+ | id | name | id | name | age | +------+----------+----+------+------+ | 1 | zhangsan | 1 | aaa | 11 | | 2 | lisi | 2 | bbb | 12 | | 3 | wangwu | 3 | ccc | 13 | | NULL | NULL | 4 | ddd | 14 | +------+----------+----+------+------+ SELECT * from left_tb l LEFT JOIN right_tb r ON l.id=r.age; +----+----------+------+------+------+ | id | name | id | name | age | +----+----------+------+------+------+ | 1 | zhangsan | NULL | NULL | NULL | | 2 | lisi | NULL | NULL | NULL | | 3 | wangwu | NULL | NULL | NULL | +----+----------+------+------+------+ SELECT * from left_tb l LEFT JOIN right_tb r ON 1=1; +----+----------+------+------+------+ | id | name | id | name | age | +----+----------+------+------+------+ | 1 | zhangsan | 1 | aaa | 11 | | 2 | lisi | 1 | aaa | 11 | | 3 | wangwu | 1 | aaa | 11 | | 1 | zhangsan | 2 | bbb | 12 | | 2 | lisi | 2 | bbb | 12 | | 3 | wangwu | 2 | bbb | 12 | | 1 | zhangsan | 3 | ccc | 13 | | 2 | lisi | 3 | ccc | 13 | | 3 | wangwu | 3 | ccc | 13 | | 1 | zhangsan | 4 | ddd | 14 | | 2 | lisi | 4 | ddd | 14 | | 3 | wangwu | 4 | ddd | 14 | +----+----------+------+------+------+
以上是关于mysql基础的主要内容,如果未能解决你的问题,请参考以下文章
[Go] 通过 17 个简短代码片段,切底弄懂 channel 基础
连接MySQL出现错误:ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)(代码片段
使用 json rereiver php mysql 在片段中填充列表视图
关于mysql驱动版本报错解决,Cause: com.mysql.jdbc.exceptions.jdbc4Unknown system variable ‘query_cache_size(代码片段