作者Ludwigvan (hi)
看板Database
标题[SQL ] 请教update的写法
时间Mon Jan 2 11:14:28 2012
先说抱歉 我的SQL是自学 不太会用专业术语
我有两个table
table_1 table_2
bookstore bookname author code code bookname author
甲书局 1 1 A 张三
甲书局 1 2 A 李四
乙书局 1 3 B 张三
乙书局 2 4 C 李四
想update成下列table
bookstore bookname author code
甲书局 A 张三 1
甲书局 A 张三 1
乙书局 A 张三 1
乙书局 A 李四 2
Code是独一无二的代号
Bookname跟author都可能重覆
请问
1. 如果我想要填入author 或bookname
是否可用
UPDATE table_1
SET table_1.author=
( SELECT table_2.author FROM table_2 where table_2.code=table_1. code)
UPDATE table_1
SET table_1.bookname=
( SELECT table_2. bookname FROM table_2 where table_2.code=table_1. code)
2. 如果我想同时输入呢?
是否是用
UPDATE table_1
SET table_1.author=
( SELECT table_2.author FROM table_2 where table_2.code=table_1. code)
AND
SET table_1.bookname=
( SELECT table_2. bookname FROM table_2 where table_2.code=table_1. code)
谢谢回答
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 219.80.238.184