0

I try to make a filter for my project. And I want to learn how can I use array values in inner join. For example I have a query like this.

SELECT Orders.OrderID, Employees.LastName, Employees.FirstName
FROM Orders
INNER JOIN Employees
ON Orders.EmployeeID = Employees.EmployeeID;

But I have multiple EmployeeIDs in array and I try to make my query like this.

SELECT Orders.OrderID, Employees.LastName, Employees.FirstName
FROM Orders
INNER JOIN Employees
ON Orders.EmployeeID = Employees.1,2,3;

this is the wrong way I know but I really don't know the right way to make this query.

1
  • Join all the employees then limit them in the where clause. ON Orders.EmployeeID = Employees.EmployeeID where Orders.EmployeeID in(1,2,3) Commented Jun 19, 2017 at 11:44

3 Answers 3

1

No need to worry about that if there are any number of rows of employee id mapped with the orders it will return that many rows if exist, rather just use a where in clause

SELECT Orders.OrderID, Employees.LastName, Employees.FirstName
FROM Orders
INNER JOIN Employees ON Orders.EmployeeID = Employees.EmployeeID 
WHERE Employees.EmployeeID IN (1,2,3);`
Sign up to request clarification or add additional context in comments.

Comments

0

You can do like this,

SELECT Orders.OrderID, Employees.LastName, Employees.FirstName
FROM Orders
INNER JOIN Employees
ON Orders.EmployeeID = Employees.EmployeeID where Employees.EmployeeID IN (1,2,3);

Inner join with employee id will fetch all matching records of both orders and employees with condition of employee id and then on that where clause to fetch those records whose employee id is 1,2,3.

Comments

0

You could use the in operator in the on clause:

SELECT Orders.OrderID, Employees.LastName, Employees.FirstName
FROM Orders
INNER JOIN Employees
ON Orders.EmployeeID = Employees.EmployeeID and Employees.EmployeeID in (1,2,3);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.