SQL join using AND

I understand how ON works in a JOIN statement however I am having trouble understanding the concept of ‘AND’ in join statements.
Can someone explain that to me or is there a visual of what that would look like?

Could you give an example of what you mean? Normally AND is just boolean logic, only do something if “a” and “b” are valid.

I think I got it. This is from code academy course using the baseball database. If both team.teamid and team.yearid don’t match from salaries table, nothing it returned?

Select sum(salary)AS salary, teams.name, salaries.yearid
from salaries
Join teams
on teams.teamid = salaries.teamid
and teams.yearid = salaries.yearid
group by teams.era, teams.name, salaries.yearid
order by sum(salary)desc;

1 Like

Ah grand. I don’t know if it’s ever introduced in the course but you can use constraints in the syntax of the join instead of using WHERE. I think this SO answer covers it nicely: sql - Using AND in an INNER JOIN - Stack Overflow if you wanted a bit more info.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.