Join Introduction [MySQL]

sql join

  • Joins tables
  • Many forms:
    • INNER JOIN (include only matching columns)
    • OUTER JOIN (include all columns)
    • LEFT OUTER JOIN
    • NATURAL JOIN
    • CONDITION JOIN
  • “JOIN” means “INNER JOIN” in MySql.

Example of a Condition Join

Statement: JOIN the CountryLanguage and Language tables using the country code

SELECT CO.Name, L.language, L.percentage        FROM Country CO  	JOIN CountryLanguage L  	  ON CO.code = L.countrycode  	WHERE ...;

Example of Multiple Table Join

SELECT CO.name, C.*, L.language  	FROM Country CO  	JOIN CountryLanguage L  	  ON CO.code = L.countrycode  	JOIN City C  	  ON CO.code = C.countrycode  	WHERE ...; /* more conditions */