Take the 2-minute tour ×

Lets say I have two tables: "user" and "grade"

my "user" table looks like this:


my "grade" table looks like this:


I want to compare "id" column from the user table with "studentid" column from grade table. If the logged in user has an id 5 then I would need to pull out studentid 5 with "names, exam1, exam2" from the grade table and display it in html format. How do I do this?

Please help, thanks.

share|improve this question

2 Answers 2

You need to JOIN both tables,

SELECT  a.*, b.*
FROM    user a
        INNER JOIN grade b
            ON a.ID = b.StudentID
WHERE   a.ID = 5

To further gain more knowledge about joins, kindly visit the link below:

share|improve this answer

Try this..

SELECT  names, 
FROM  grade g
   INNER JOIN user u
      ON u.id = g.studentid
WHERE u.id = 5
share|improve this answer

Your Answer


