So, after having the problem with ghost unread mail appearing on my iPhone, I then had to deal with this on the Mac Mail app.
This has happened before, and can usually be simply fixed by clicking on the offending folder (usually Inbox), then clicking on ‘Mailbox’ in the menu bar, then clicking on ‘Rebuild’
it takes a little while but usually resolves the issue, this also works pretty well if the inbox is showing no messages at all, just a blank window, anyway, back to the problem, so this time, this didn’t work, so I had to resort to a more drastic rebuild.
First, quit Mail
Once it is no longer running, click on Finder
then press SHIFT, CMD, G
then paste in the following location and click on Go
In that folder you need to remove all files starting with Envelope (usually Envelope Index, Envelope Index-shm, Envelope Index-wal), normally, I move these to the Desktop until everything is all working again
Once there are no files starting with Envelope in that location, then click on Mail to Rebuild the Index, Once this has finished, your mail should be back to normal, no missing unread items.