简体   繁体   中英

Join two table to be one record

i have two table like this 在此处输入图片说明 and I want to join these two tables into this

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

Thanks for helping.

Simply Use Inner Join

SELECT A.*, B.UAS
FROM tbl1 AS A JOIN tbl2 AS B ON A.StudentID = B.StudentID AND A.SubjectID = B.SubjectID
SELECT t1.*, t2.UAS
    FROM uts AS t1 
    LEFT JOIN uas AS t2
        ON t1.StudentID = t2.StudentID AND t1.SubjectID = t2.SubjectID

You just have to join the two tables on the two common columns.

A JOIN clause is used to combine rows from two or more tables, based on a related column between them.

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

for details about join you can read some tutorials https://www.w3schools.com/sql/sql_join.asp

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