How to Join tables on common columns

mysql> select lookup.illustrationid, lookup.personid,person.birthday from lookup left join person on lookup.personid=person.personid=statement to join birthday in person table with primary illustration id

In MySQL, you can join tables on common columns using the JOIN clause in a SELECT statement. The common columns are specified in the ON clause. There are different types of joins, including INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN. Here’s a basic example using INNER JOIN:

sql
SELECT *
FROM table1
INNER JOIN table2 ON table1.common_column = table2.common_column;

In this example, replace table1 and table2 with the actual names of your tables, and replace common_column with the actual column that is common between the two tables.

Here are brief explanations of some common types of joins:

  • INNER JOIN: Returns only the rows where there is a match in both tables.
  • LEFT JOIN (or LEFT OUTER JOIN): Returns all rows from the left table and the matched rows from the right table. If there is no match, NULL values are returned for columns from the right table.
  • RIGHT JOIN (or RIGHT OUTER JOIN): Returns all rows from the right table and the matched rows from the left table. If there is no match, NULL values are returned for columns from the left table.
  • FULL JOIN (or FULL OUTER JOIN): Returns all rows when there is a match in either the left or the right table. If there is no match, NULL values are returned for columns from the table without a match.

Here’s an example of a LEFT JOIN:

sql
SELECT *
FROM table1
LEFT JOIN table2 ON table1.common_column = table2.common_column;

Adjust the join type based on your specific requirements and the data you want to retrieve.