What join should i use for joining these 2 tables?

**I am just beginner learning database php mysql and I am confused what join should I use in this. I have my foreign key which is the ExamineeID and I want these both table to be join together. But I do not know how to do it nor what join should I use. These are my tables: **

Table 1:

Table 2:
ScoreID
Score
Rank
ExamTime
ExamineeID

I want to join them both, and it is okay if the ScoreID is not on the table, but the most important that can be included is the Score, Rank, ExamTime, ExamineeID and all of the columns in Table 1.

SELECT col1, col2, col3 FROM table1 JOIN table2 ON table1.ExamineeID = table2.ExamineeID

col1, col2, col3 should be replaced by the columns you like to get in your result.

You can also use aliases which make the notation a bit shorter and more clear

SELECT a.col1, b.col1, b.col2 FROM table1 a JOIN table2 b ON a.ExamineeID = b.ExamineeID

As you can see i gave table1 the alias a and table2 the alias b. And in the SELECT clause i used the aliases to select columns from both tables.

Instead of the Join which is a INNER JOIN there are some other join types like LEFT JOIN, RIGHT JOIN and OUTER JOIN. If you google on mysql join types you could find plenty tutorials explaining the differences

1 Like

2 Likes
Sponsor our Newsletter | Privacy Policy | Terms of Service