SQL查询的正确语法

SQL查询的正确语法,sql,Sql,我在SQL DB中有两个表: SUBJECT(idSUB,nameSUB); TOPIC(idTOP,nameTOP,idSUB); 我想要的是: + select COUNT(*) from TOPIC as numTOPIC group by idSUB--> as a Temp table + then join 2 table Temp and SUBJECT --> a new table(idSUB,nameSUB,numTOPIC) 但是我已经尝试了很多次,但是我真

我在SQL DB中有两个表:

SUBJECT(idSUB,nameSUB);
TOPIC(idTOP,nameTOP,idSUB);
我想要的是:

+ select COUNT(*) from TOPIC as numTOPIC group by idSUB--> as a Temp table
+ then join 2 table Temp and SUBJECT --> a new table(idSUB,nameSUB,numTOPIC)
但是我已经尝试了很多次,但是我真的不知道这个SQL查询的确切语法。
救命啊

您可以使用
左连接
主题
主题
连接起来

SELECT  a.idsub, a.namesub,
        COUNT(b.idsub) numTOPIC 
FROM    subject a
        LEFT JOIN topic b
            ON a.idsub = b.idsub
GROUP   BY a.idsub, a.namesub