You might have a reason to write a query letter, because you’d like a book contract instead of publishing yourself. To assemble a query, look to the four Cs. Those are the basic parts of a query: Connect, Context, Compel, Credentials.
Connection is the place where you make it clear to an agent or editor you’re not just throwing the spaghetti against the wall. You researched them.
Context tells an agent where in the bookstore your book would sit. Make sure the agent understands that. It’s where you offer comparison titles.
Compel is the biggest part of the letter. You’re compelling the agent or editor to ask for more of your book, because the story’s got them hooked. Go online, or go to your bookshelf, and look at jacket copy, because that's what that copy is: compel.
Credentials show who you are and why are you writing this book. If you’re already published, have placed some short fiction in a journal, or you have a writing degree, or work in the field where your book is placed, this is the spot to say so.
A query letter calls on your power of summary and your power of persuasion. You can create yours one C at a time.