私は2つのテーブルを持っています:
Table1
:
RulesVectorID(nullable, primary),Weight,IsDeleted
Table2
:
RulesVectorID(forigen) , Weight,IsDeleted, NumberOfOffers, other fields...
私は2つのことをしたい:
Id
table1 のすべての行に割り当てるwhere RulesVectorID ==null
私はこれを試しました:
UPDATE myTable1 SET RulesVectorID = SELECT MAX(RulesVectorID) + 1 FROM myTable1, WHERE RulesVectorID IS NULL
手順 (1) で追加した行に、その
Weight, IsDeleted
列をコピーして 1 を追加したいNumberOfOffers
私はこれを試しました:
INSERT INTO myTable2 (Weight, IsDeleted, NumberOfOffers, RulesVectorID) VALUES ( SELECT Weight, IsDeleted, 1, RulesVectorID FROM myTable1 WHERE myTable1.RulesVectorID NOT IN (SELECT RulesVectorID FROM myTable2))
それを行うためのよりクリーンな方法はありますか?