将两个表连接为一条记录

lsmepo6l  于 2021-06-20  发布在  Mysql
关注(0)|答案(3)|浏览(323)

我有两张这样的table

我想把这两个表合并到这个表中

  1. Student ID SubjectID UTS UAS
  2. 1 1 80 80
  3. 1 2 88 88

谢谢你的帮助。

ffscu2ro

ffscu2ro1#

join子句用于基于两个或多个表之间的相关列来组合这些表中的行。

  1. select t1.*,t2.UAS from table1 t1
  2. inner join table2 t2
  3. ON t1.StudentID = t2.StudentID AND
  4. t1.SubjectID = t2.SubjectID

有关加入的详细信息,您可以阅读一些教程https://www.w3schools.com/sql/sql_join.asp

fgw7neuy

fgw7neuy2#

只需使用内部连接

  1. SELECT A.*, B.UAS
  2. FROM tbl1 AS A JOIN tbl2 AS B ON A.StudentID = B.StudentID AND A.SubjectID = B.SubjectID
ht4b089n

ht4b089n3#

  1. SELECT t1.*, t2.UAS
  2. FROM uts AS t1
  3. LEFT JOIN uas AS t2
  4. ON t1.StudentID = t2.StudentID AND t1.SubjectID = t2.SubjectID

您只需将两个表连接到两个公共列上。

相关问题