user7407984
user7407984

Reputation:

get name from one table with match id in another table?

I don't know how to solve this problem:

I have two tables

1st table :

register

=====================================================
ID       NAME    Mailid      Subject_id    username..password etc
-----------------------------------------------------
34       John     xx          1             xxx
17       Mike    xxx          2             xxx
5        Alan    xxx          4             xxx
10       Dave    xxxx         3             xxxx

2nd table

subject_id      subject       
  1              maths    
  2              science
  3             chemistry
  4              physics

and I want to get result like this

ID       NAME    Mailid      Subjectname    username..password etc
-----------------------------------------------------
34       John     xx           maths              xxx
17       Mike    xxx          science             xxx
5        Alan    xxx          physics            xxx
10       Dave    xxxx         chemistry          xxxx

Instead of subject id, I want subject name.

Upvotes: 0

Views: 4148

Answers (1)

Rendy Eko Prastiyo
Rendy Eko Prastiyo

Reputation: 1098

table1 = your first table containing user detail.

table2 = your second table containing subject detail.

SELECT table1.id, table1.name, table1.mailid, table2.subjectname, table1.username, table1.password, ......
FROM table1
LEFT JOIN table2 ON table1.subject_id = table2.subjectname
GROUP BY table1.id

Upvotes: 3

Related Questions