[SQL ] 請教update的寫法

看板Database作者 (hi)時間12年前 (2012/01/02 11:14), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
先說抱歉 我的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
文章代碼(AID): #1F0I4NsR (Database)
文章代碼(AID): #1F0I4NsR (Database)