Reputation: 878
I have 2 tables in SQL DB:
SUBJECT(idSUB,nameSUB);
TOPIC(idTOP,nameTOP,idSUB);
All I want is:
+ 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)
But I've tried many time but I really dont know the exactly syntax of this SQL query. Help!
Upvotes: 1
Views: 68
Reputation: 263693
You can use LEFT JOIN
to join subject
with topic
.
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
Upvotes: 2