Keep in mind that even if the job would have been perfect for you, the company probably interviewed multiple people, and selected one that they thought would be more perfect for them.
I recently did a round of hiring for my team, and we had several excellent candidates, but could only hire one, so we made a choice.
It’s always sad (for me) because I tend to see the potential in almost everybody, and wish we could hire all the people.