user1916224 user1916224 - 7 months ago 17
SQL Question

count using inner join from 2 tables

I have 2 tables

Document_type_de
and the other is
document
.
Document
table has all the documents stored but which type of document it is, is defined in
document_type_de
, so i need help with the query which will help me find the count of the documents of each type in the document table.

columns under document_type_de table

ID, display name


columns under document table

documenttypede

Answer

This'll do it:

SELECT Type.[Display Name], 
       COUNT(*) AS [Number of Documents]
FROM Document_type_de Type
JOIN Document D
    ON Type.ID = D.documenttypede
GROUP BY Type.[Display Name]
ORDER BY Type.[Display Name]
Comments