a表和b表 简单的inner join
SELECT a.id as aid, a.name as aname, a.state astate,
b.id as bid, b.name as bname, b.state bstate
FROM a
INNER JOIN b on b.ida.id简单的left join
SELECT a.id as aid, a.name as aname, a.state astate,
b.id as bid, b.name as bname,…
今天在写一个sql的时候,碰到一个知识盲区,也是我对 left join 理解的错误。 一、表结构
学生表
CREATE TABLE stu ( id varchar(50) NOT NULL COMMENT 主键ID,name varchar(50) NOT NULL COMMENT 学生姓名,PRIMARY KEY (id) USING BTREE
) ENGINEInnoD…
如图: T1表IDNAMEAGE1张三112李四123王五13T2表IDNAMECOURSE3张三语文4张三数学5马六英语1、ID关联(LEFT JOIN)
SELECT * FROM T1 LEFT JOIN T2 ON T1.IDT2.ID
结果如图: 联系两个表: 分析:以T1表&#x…
创建实验环境
create database test;use test;create table ta (aid int(1),aname(5));insert into ta values(1,1001);
insert into ta values(2,1002);
insert into ta values(3,1003);
insert into ta values(4,1004);
insert into ta values(5,1005);create table tb (bid…
1. 执行语句,创建3张表
CREATE TABLE table_dev1 (id serial NOT NULL,devicecode text NULL, -- 设备idopenflag int4 NULL -- 是否启动 1:启动, 0:未启动
);CREATE TABLE table_dev2 (id serial NOT NULL,devicecode text NULL, -…