2013-11-20 2 views
0

다음 세 테이블이 있습니다. Data_Excel에는 사람의 이름, 주소, 도시 및 출처가 포함되어 있습니다. Person 테이블에는 이름과 ID가 있습니다. 나는 모든 세부 사항을 얻을 수 person_location에 data_excel 테이블에 일치해야 ID 인 존재 ID는 사람이 테이블 이름에서 유래 주소 소스, 주소, 도시와 ID를 ... 삽입해야SQL 여러 테이블 중에서 선택하여 삽입

I have the following 3 tables, Data_Excel contains the names, address, city and source of person; Person table has the name and ID; I need to insert into person_location the address source, address, city and ID...where ID comes from person table and name that exist against the id should be matched in the data_excel table to get all the details

+3

지금까지 해보신 것은 무엇입니까? 예상되는 결과를 제공하지 않는 쿼리가 있습니까? – Walls

+0

선택 A.ID, A.P_name, 소스, P_address, P_city, P_country 에서 A.name, A.ID이 data_excel, 사람 A로부터 I (ID를 선택하고, 이름 사람 ID> 6566 에서) 이런 식으로 선택하려고했지만 오류가 발생했습니다 –

답변

1

자신의 문제에 적용해야하는 정보를 제공해야하는 very similar question을 살펴보십시오.

+0

이름과 일치하는 이름을 확인하여 관련 값을 얻는 방법은 무엇입니까? –

1

오류는 당신이 ID > 6566 조건이 필요하면, 당신은 마지막에 추가 할 수 있습니다

INSERT INTO person_location 
SELECT A.ID,A.P_name,source,P_address,P_city,P_country from data_excel de, person A where A.name = de.c_name; 

.. 쿼리 A.name, A.ID in (Select[...]

당신은 시도 할 수 있습니다이 부분에서 아마이다.

INSERT INTO person_location 
SELECT A.ID,A.P_name,source,P_address,P_city,P_country from data_excel de, person A where A.name = de.c_name and ID > 6566; 
+0

"열이 모호하게 정의 됨" –

+2

원하는 테이블에 따라'SELECT'에서'source'를'A.source' 또는'de.source'로 대체하십시오. – RMK

+0

선택 A.ID, A.Name, de.source, de.P_address, de.P_city, data_excel 드, 사람으로부터 de.P_Country A.name = de.P_Name 및 ID가> 6566 이 감사를 작동 ... –

관련 문제