我有兩個表具有一對多關係表1(一),表2(很多)。Mysql插入從條件和限制的另一個表
table1 has (t1_id) as KEY
table2 has (t2_id) as KEY and t2_t1_id as as refference to table1
現在table1
我需要擁有table2
的id
列(rand_t2_id
),我真的不關心哪一個
這是我嘗試
INSERT INTO table1 (rand_t2_id)
SELECT t2_id
FROM table2
WHERE table1.t1_id = table2.t2_t1_id;
還有查詢如果需要的話,需要在某處進行限制構建。我只需要表2中的一個ID
在這裏沒有運氣壽,任何人都知道一個修復?
你是什麼意思,你不關心哪個t2_id是從每個rand_t2_id引用的? – 2012-04-24 07:36:36
對不起,如果你們不明白。我很高興有人做到了。 – 2012-04-24 07:44:08