will give you the result that you want. I dont know the result set how you are having but i tested with the sample you gave..
index=main sourcetype=xxx|multikv fields code,hash,count|stats sum(count) as total_count by code,hash|join code [search index=main sourcetype=xxx|multikv fields code,message|fields code,message]|table code,,message,hash,total_count
... View more