mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
fixed update with subselect (FOR REVIEW)
This commit is contained in:
@ -205,3 +205,19 @@ SELECT (SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03')
|
||||
(SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03')
|
||||
2002-08-03
|
||||
drop table searchconthardwarefr3;
|
||||
create table t1 (a int NOT NULL, b int, primary key (a));
|
||||
create table t2 (a int NOT NULL, b int, primary key (a));
|
||||
insert into t1 values (0, 10),(1, 11),(2, 12);
|
||||
insert into t2 values (1, 21),(2, 22),(3, 23);
|
||||
select * from t1;
|
||||
a b
|
||||
0 10
|
||||
1 11
|
||||
2 12
|
||||
update t1 set b= (select b from t2 where t1.a = t2.a);
|
||||
select * from t1;
|
||||
a b
|
||||
0 NULL
|
||||
1 21
|
||||
2 22
|
||||
drop table t1, t2;
|
||||
|
@ -110,4 +110,15 @@ EXPLAIN SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03';
|
||||
EXPLAIN SELECT (SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03');
|
||||
SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03';
|
||||
SELECT (SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03');
|
||||
drop table searchconthardwarefr3;
|
||||
drop table searchconthardwarefr3;
|
||||
|
||||
#update with subselects
|
||||
create table t1 (a int NOT NULL, b int, primary key (a));
|
||||
create table t2 (a int NOT NULL, b int, primary key (a));
|
||||
insert into t1 values (0, 10),(1, 11),(2, 12);
|
||||
insert into t2 values (1, 21),(2, 22),(3, 23);
|
||||
select * from t1;
|
||||
update t1 set b= (select b from t2 where t1.a = t2.a);
|
||||
select * from t1;
|
||||
drop table t1, t2;
|
||||
|
||||
|
Reference in New Issue
Block a user