简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM