[英]Create Table3 AS SELECT WHERE id from table1 = id from table2
我嘗試過的
CREATE TABLE temporary_bundle_wired
AS SELECT * FROM temporary_bundle,wired_items
WHERE temporary_bundle.id = wired_items.id;
我有兩個現有的表:
temporary_bundle
wired_items
我想創建第三個表,名為temporary_bundle_wired
。 在此表中,我想插入來自temporary_bundle WHERE temporary_bundle.id = wired_items.id
所有行(及其列和字段),在temporary_bundle WHERE temporary_bundle.id = wired_items.id
我也想從刪除這些記錄temporary_bundle
一旦我搬到他們到tempoary_bundle_wired
。
我嘗試過的查詢返回:
duplicate column name Id
問題在於兩個表都有一個名為id的列,您正在選擇兩者以創建新表。 您將必須指定其中一個表的每一列,因此您可以重命名id列:
CREATE TABLE temporary_bundle_wired
AS SELECT a.id as 'othername', user_id, base_item, ..., b.*
FROM temporary_bundle a, wired_items b
WHERE temporary_bundle.id = wired_items.id;
干杯。
我嘗試過的查詢返回:
duplicate column name Id
上面的錯誤公然表明您有重復的列。 您正在創建的新表中的列名(id)
在兩個舊表的公共屬性( temporary_bundle.id
wired_items.id
和wired_items.id
)之間沖突
確保兩個表之間沒有其他公共屬性。 如果存在,則在插入之前從任何一個表中為其別名。
如果其他人不起作用,請嘗試此操作。
CREATE TABLE temporary_bundle_wired
AS
SELECT
t.id as id, user_id, base_item, extra_data, x, y, z, rot, wall_pos, limited_number, limited_stack, sandbox -- and all other attributes you want
FROM temporary_bundle t, wired_items w
WHERE t.id = w.id;
刪除-這是一個完全不同的查詢。
DELETE from temporary_bundle t WHERE t.id = (select id from wired_items);
一個問題確實是兩個表之間的id
相同。 其他列也可以,但是如果id
是唯一的問題,請使用using
子句:
CREATE TABLE temporary_bundle_wired AS
SELECT *
FROM temporary_bundle JOIN
wired_items
USING (id);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.