Answer the question
In order to leave comments, you need to log in
How to use INNER JOIR on two tables based on 3rd table?
There are 3 tables in the database.
Companies - contains information about existing companies.
Accounts - contains account information.
Employees - links the Companies and Accounts tables saying that a certain employee works for a certain company.
I have an Employee object stored in the session, which contains the employee_id, company id and current user account id fields.
Next , I want to create a stored procedure that accepts employee_id, which will find the company_id link from the Employees table; account_id and will display all columns from the Companies and Accounts tables for the given user.
How to extract information about the user and his company using JOIN (INNER JOIN)?
Here's what came to mind:
SELECT company_name, account_first_name, account_last_name, account_login
FROM accounts
INNER JOIN companies ON company_id = 21 AND account_id = 28;
...
SELECT account_id, company_id
FROM employees
WHERE employee_id = 3;
// результат company_id = 21, account_id = 28
SELECT company_name, account_first_name, account_last_name, account_login
FROM accounts
INNER JOIN companies ON company_id = 21 AND account_id = 28;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question