使用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)
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下