I'm in the midst of writing an SQL statement and I have a problem joining both tables (let's call it Table Enrollment & Product) based on a foreign key column from table Enrollment's column StudentID. The StudentID is read from a variable $StudentID.
Enrollment table
+--------------+-----------+-----------+
| EnrollmentID | StudentID | ProductID |
+--------------+-----------+-----------+
| 1            | 5         | 1         |
| 2            | 5         | 2         |
|3             | 7         | 2         |
|4             | 7         | 3         |
|5             | 9         | 5         |
+--------------+-----------+-----------+
Product Table
+-----------+-------------+------------+
| ProductID | ProductName | ProductDate|
+-----------+-------------+------------+
|1          | ProductA    | 1/1/2017   |
|2          | ProductB    | 1/2/2017   |
|3          | ProductC    | 1/3/2017   |
|4          | ProductD    | 1/4/2017   |
+-----------+-------------+------------+
This is the SQL statement so far i've come up and having trouble with:
"SELECT product.ProductName, product.ProductDate
                                FROM enrollment WHERE StudentID = '$StudentID'
                                RIGHT JOIN product ON enrollment.productid = product.productid";
If $StudentID is 5. I want it to display all items from ProductID that is associated with StudentID 5. Which in this case, Product A and Product B will be the output.
 
     
    