2011-12-06 110 views
0

我正在爲我的數據庫創建一個視圖,我正在連接3個表,用戶,personal_info和contact_info,如果您發現我的Select語句中有很多列名稱,因爲我不想包含主鍵但它看來我這裏有一個錯誤,看看如何在MySQL中加入3個表?

CREATE VIEW `payroll`.`new_view` AS 
Select employee_id,employee_password,First_Name,Middle_Initial, 
Last_Name,Date_Of_Birth,Beneficiaries,Home_Number,Address,Mobile_Number,Email_Address 
From USER 
LEFT JOIN personal_info on idUser = idPersonal_Info, 
FULL JOIN contact_info on idUser = idContact_Info 

的誤差

ERROR 1146: Table 'payroll.full' doesn't exist 

SQL Statement: 

CREATE OR REPLACE VIEW `payroll`.`new_view` AS 

Select employee_id,employee_password,First_Name,Middle_Initial, 

Last_Name,Date_Of_Birth,Beneficiaries,Home_Number,Address,Mobile_Number,Email_Address 

From USER 

LEFT JOIN personal_info on idUser = idPersonal_Info, 

FULL JOIN contact_info on idUser = idContact_Info 
+0

ü可以添加每個表的結構?因爲很難找出哪些列屬於哪個表。 – Shirish11

+1

MySQL中沒有'FULL JOIN'。你必須用'LEFT'和'RIGHT'加入'UNION'來模擬它。 –

+0

您也有一個無意義的逗號,後面是:'LEFT JOIN個人信息關於idUser = idPersonal_Info,' –

回答

0

錯誤的:

LEFT JOIN的personal_info上ID用戶= idPersonal_Info

你需要指定哪個表相當於在其他表,其中一個列,例如

SELECT a,b,c from table1 
    LEFT JOIN table2 
    on table1.a= table2.columnY 
你的情況

on USER.idUser = Personal_Info.idPersonalInfo 

與同爲第三個加入

另一件事是行末的逗號:

LEFT JOIN personal_ info on idUser = idPersonal_Info

它不屬於那裏。

+0

如果沒有衝突,則沒有必要這樣做。但這是一個很好的建議,爲了清晰和維護。 –

0

與backtics報價是:payroll.new_view

CREATE VIEW `payroll.new_view`