简体   繁体   English

从一个表中获得名称,在另一个表中具有匹配ID?

[英]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. 我想要的是主题名称,而不是主题ID。

table1 = your first table containing user detail. table1 =您的第一个包含用户详细信息的表。

table2 = your second table containing subject detail. table2 =包含主题详细信息的第二张表。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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