Consider two tables:
Employees:
id | name
1 | Alice
2 | Bob
3 | Carol
Departments:
emp_id | department
1 | Sales
3 | HR
4 | IT
What rows will this query return?
SELECT Employees.name, Departments.department
FROM Employees
INNER JOIN Departments ON Employees.id = Departments.emp_id;
SELECT Employees.name, Departments.department FROM Employees INNER JOIN Departments ON Employees.id = Departments.emp_id;
INNER JOIN returns only rows with matching keys in both tables.
The INNER JOIN matches Employees.id with Departments.emp_id. Only Alice (id=1) and Carol (id=3) have matching department entries. Bob (id=2) has no department, and emp_id=4 in Departments has no matching employee.
Choose the correct statement about INNER JOIN in SQL.
Think about what 'inner' means in INNER JOIN.
INNER JOIN returns only rows where the join condition matches in both tables. It excludes rows without matches.
Identify the query with valid INNER JOIN syntax.
Check the JOIN clause and ON condition syntax carefully.
Option B uses correct INNER JOIN syntax with ON and single equals sign. Option B misses ON keyword. Option B uses USING which is valid in some SQL dialects but not standard SQL. Option B uses double equals which is invalid in SQL.
You have two large tables joined by a foreign key. Which method improves INNER JOIN query speed?
Think about how databases find matching rows quickly.
Indexes on join columns help the database quickly locate matching rows, improving performance. SELECT * can slow queries by returning unnecessary data. Removing filters increases data processed. CROSS JOIN returns all combinations, which is slower.
Given these tables:
Table A: id, value
Table B: id, description
Query:
SELECT A.id, B.description
FROM A INNER JOIN B ON A.id = B.idd;
What error will this query produce?
Check the column names used in the ON clause carefully.
The column 'idd' does not exist in table B, so the database will raise an error about the missing column.