In a SparePart table the uniqueness of the rows is given from a combination of materialName and materialNumber , what i want to do is get the total number of Spare Parts avalaible now.
I have tried using count(distinct …) but it only works for one field not two.
The SQL query(using hibernate query language) with an inner query would look like this :
select count(*) from (
select distinct materialName, materialNo from SparePart
) as col
Use a subquery+group by and then filter for the first ID that represents the particular group, finally count all those that match the filter: