표 2

2017-09-04 5 views
0

에서 = ID 표에서 ID가 나는 시도 무엇 표 3 AS SELECT 만들기 temporary_bundle_wired이라는 세 번째 테이블을 만들고 싶습니다. 이 표에서 나는 나 또한 내가 tempoary_bundle_wired로 이동 한 후 temporary_bundle에서 레코드를 삭제하려면 temporary_bundle WHERE temporary_bundle.id = wired_items.id표 2

에서 모든 행 (및 열 및 필드)를 삽입 할.

쿼리 내가 시도 반환 :

duplicate column name Id

답변

1

쿼리 내가 시도 반환 : 이 duplicate column name Id

위의 오류가 노골적으로 나타냅니다를 중복 열이 있습니다. 작성중인 새 테이블의 열 이름 (id)

두 테이블 사이에 다른 일반적인 속성이 없는지 확인이 된 테이블 '공통 속성 (temporary_bundle.idwired_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; 

DELETING - 이것은 서로 다른 검색어입니다.

DELETE from temporary_bundle t WHERE t.id = (select id from wired_items); 
1

문제는 두 테이블은 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; 

건배.

+0

http://prntscr.com/gh1vfo. 그래서 쿼리의 각 열에 대해 할 것입니다 ... SELECT 'a_id'로 'temporary_bundle.id', 'user_id', 'room_id'등? – buuencrypted

+0

예. 올바른지 – sdsc81

+0

CREATE TABLE temporary_bundle_wired 'id', 'user_id', 'base_item', 'extra_data', 'x', 'y', 'z', 'rot', 'wall_pos' limited_number ','limited_stack ','sandbox 'FROM temporary_bundle a, wired_items b WHERE a.id = b.id; ... 이것은 temporary_bundle에서 행을 삽입하지 않았습니다. 여기서 temporary_bundle.id = wired_items.id입니다. 그것이 한 것은 http://prntscr.com/gh254q입니다.또한 temporary_bundle에서 해당 필드를 채울 필요가 있습니다. – buuencrypted

0

실제로 두 가지 표에서 id이 같은 문제가 있습니다. 다른 열뿐만 아니라 수 있지만 id 인 경우 유일한 문제는 다음 using 절 사용

CREATE TABLE temporary_bundle_wired AS 
    SELECT * 
    FROM temporary_bundle JOIN 
     wired_items 
     USING (id);