1
0
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:
bell@sanja.is.com.ua
2002-10-24 22:59:29 +03:00
parent 0ca3212a8c
commit 21ca25debf
8 changed files with 63 additions and 15 deletions

View File

@ -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;

View File

@ -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;