記錄一下MySQL的連線

大大只植物發表於2024-04-30

簡單的2張表演示

1.左連線

SELECT CustomerPro.ID,CustomerPro.CustomerName,Employee.EmployeeName
FROM CustomerPro
LEFT JOIN Employee 
on CustomerPro.EmployeeID=Employee.ID

2.右連線

SELECT CustomerPro.ID,CustomerPro.CustomerName,Employee.EmployeeName
FROM CustomerPro
RIGHT  JOIN Employee 
on CustomerPro.EmployeeID=Employee.ID

3.內連線

SELECT CustomerPro.ID,CustomerPro.CustomerName,Employee.EmployeeName
FROM CustomerPro,Employee 
WHERE CustomerPro.EmployeeID=Employee.ID
這2種其實都是內連線的寫法
SELECT CustomerPro.ID,CustomerPro.CustomerName,Employee.EmployeeName
FROM CustomerPro
inner JOIN Employee
on CustomerPro.EmployeeID=Employee.ID

相關文章