使用JOINS从表A中不存在的表A中的MySQL SELECT?
要从表B中不存在的表A中进行SELECT,可以使用左连接。以下是语法-
select yourTableNameA.* from yourTableNameA left join yourTableNameB on yourTableNameA.yourColumnName = yourTableNameB.yourColumnName where yourTableNameB.yourColumnName IS NULL;
让我们首先创建一个表。以下是查询-
<table_A>
mysql> create table table_A -> ( -> Value int -> );
以下是使用insert命令在表中插入记录的查询-
mysql> insert into table_A values(10); mysql> insert into table_A values(15); mysql> insert into table_A values(35); mysql> insert into table_A values(45);
以下是使用select语句显示表中所有记录的查询-
mysql> select *from table_A;
这将产生以下输出-
+-------+ | Value | +-------+ | 10 | | 15 | | 35 | | 45 | +-------+ 4 rows in set (0.00 sec)
让我们创建另一个表。以下是查询-
<table_B>
mysql> create table table_B -> ( -> Value int -> );
以下是使用insert命令在表中插入一些记录的查询-
mysql> insert into table_B values(10); mysql> insert into table_B values(20); mysql> insert into table_B values(35); mysql> insert into table_B values(60);
以下是使用select语句显示表中所有记录的查询-
mysql> select *from table_B;
这将产生以下输出-
+-------+ | Value | +-------+ | 10 | | 20 | | 35 | | 60 | +-------+ 4 rows in set (0.00 sec)
以下是使用LEFTJOIN从表B中不存在的表A中选择的查询-
mysql> select table_A.* -> from table_A left join table_B on table_A.Value = table_B.Value -> where table_B.Value IS NULL;
这将产生以下输出-
+-------+ | Value | +-------+ | 15 | | 45 | +-------+ 2 rows in set (0.04 sec)
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短