I am unclear if an anchor tag should come before a query string or after.
Or does it matter?
Best practice is to append the named anchor at the end. The technical name is a fragment identifier, and the syntax is in RFC 3986.
The RFC section is here: http://tools.ietf.org/html/rfc3986#section-4.1
Wikipedia actually covers it well: