Introduction
INNER JOIN with multiple conditions helps you combine rows from two tables only when all the conditions match. It lets you be more specific about how tables relate.
Jump into concepts and practice - no test required
SELECT columns FROM table1 INNER JOIN table2 ON table1.columnA = table2.columnA AND table1.columnB = table2.columnB;
SELECT * FROM Employees INNER JOIN Departments ON Employees.DepartmentID = Departments.ID AND Employees.Location = Departments.Location;
SELECT Orders.OrderID, Customers.Name FROM Orders INNER JOIN Customers ON Orders.CustomerID = Customers.ID AND Orders.Status = 'Completed';
CREATE TABLE Students ( StudentID INT, Name VARCHAR(50), Class VARCHAR(10) ); CREATE TABLE Scores ( StudentID INT, Class VARCHAR(10), Score INT ); INSERT INTO Students VALUES (1, 'Alice', 'Math'); INSERT INTO Students VALUES (2, 'Bob', 'Science'); INSERT INTO Students VALUES (3, 'Charlie', 'Math'); INSERT INTO Scores VALUES (1, 'Math', 85); INSERT INTO Scores VALUES (1, 'Science', 90); INSERT INTO Scores VALUES (2, 'Science', 88); INSERT INTO Scores VALUES (3, 'Math', 92); SELECT Students.Name, Scores.Score FROM Students INNER JOIN Scores ON Students.StudentID = Scores.StudentID AND Students.Class = Scores.Class;
INNER JOIN with multiple conditions do in SQL?Orders and Customers?Employees and Departments with columns Employees.DeptID, Departments.ID, and Departments.Location, what will this query return?SELECT Employees.Name, Departments.Name FROM Employees INNER JOIN Departments ON Employees.DeptID = Departments.ID AND Departments.Location = 'NY';
SELECT * FROM Products INNER JOIN Suppliers ON Products.SupplierID = Suppliers.ID, Products.Category = Suppliers.Category;
Orders(OrderID, CustomerID, Status) and Customers(CustomerID, Country, Status). You want to find orders where the customer is from 'USA' and both order and customer have the same status. Which query correctly uses INNER JOIN with multiple conditions?