mysql
Apply JOIN on multiple columns of the tables MySql
You can easily apply multiple JOIN conditions while joining two tables. You can use OR operator or AND operator for this purpose.
--using OR operator
Select
employee.name, employee.email, employee_address.street
FROM Employee
INNER JOIN employee_address
ON employee.Id = employee_address.employee_id
OR employee.pincode = employee_address.street_code
OR employee.parmanent_code = employee_address.location_code
--using AND operator
Select
employee.name, employee.email, employee_address.street
FROM Employee
INNER JOIN employee_address
ON employee.Id = employee_address.employee_id
AND employee.pincode = employee_address.street_code
AND employee.parmanent_code = employee_address.location_code
Was this helpful?
Similar Posts