There are a ton of different ways to write a query letter, but a few things are universal. Make sure it's a legible font, usually Times New Roman in 12-point, left-justified. Here are the other major things you should put in your query:
1) Get the agent/editor's name right! That includes spelling and gender.
2) Include story name, genre, word count, and if you're writing for category romance, which line you're targeting. Don't bother comparing your work to a known author's - it may turn the agent/editor off, especially if he/she dislikes that author. Let your work speak for itself.
3) Touch on your hero/heroine's inner conflicts, their external conflicts toward one another, and the basic story conflict. This is important in romance. I usually start my query with an introduction paragraph, including story title, etc. I then reserve one paragraph for the heroine & her baggage, one for the hero & his, and then in the fourth paragraph, briefly describe the story conflict, why the hero/heroine are drawn to each other, and the hurdles they must overcome together. In the fifth paragraph, I mention any awards I've won for my writing, writing group memberships such as RWA, and whether I've been to conferences and workshops. Some agents/editors recommend that you don't mention you're unpublished. Always close by thanking the agent/editor.
4) Your contact information! Don't forget to finish your letter with your name, address, phone, and E-mail. They can't contact you if they don't know where you are. Omission of this info is an all-too-common occurrence, which inevitably results in your manuscript finding the recycle bin.
5) A SASE for reply, and/or return of your manuscript if you wish. If you don't include the SASE, an agent/editor will not reply to you (although some may take the time to E-mail you if an address is provided and a SASE isn't - but always include a SASE anyway). If your SASE is only letter-sized, they will reply with a rejection letter or (you can hope) a request for more material. If your SASE is big enough for your partial, they'll send it back - but not always with comments on it, so I generally don't waste postage money on asking for its return. They'll usually recycle your partial if you don't want it back.
6) At the bottom of the letter, I list the enclosures, which usually reads "Enc: First three chapters, 10-page synopsis, SASE" or something similar. This way, when I copy the letter for my files, I can keep a record of what's gone to whom.
7) Keep all of this info to a maximum of one page only. The agent or editor's time is valuable. Keep it short and sweet.
You don't need to go into great detail in a query letter. It's just a "blurb" to whet their appetites. Some agents/editors want you to query with a partial (your first three chapters) and synopsis included, and some just want the query letter itself. Always defer to the agent/editor's query and submission policies. If they don't read your genre or their house doesn't accept your kind of work, don't query - you won't be the exception to the rule.