If you don't get the job, then it wasn't meant to be. Someone else was better qualified, more experienced, or a better fit for the organization. Don't beat yourself up, be gracious in defeat. But if you really like the company or the role, take the time to write to the interviewers, asking for feedback, and how you can improve your skills and experience for the next time. And if it was your dream job, follow the organization on social media. Develop your CPD plan to have the skills and experience that that organization requires and then apply it in a year or so as time.
But sometimes when you're offered the job, you shouldn't take it. If something doesn't feel quite right about the organization or the job, or they seem desperate to get you then think twice before leaping in at the deep end. Find out more in the section.