My knowledge of SQL has been mostly gathered through immediate need as opposed to formal training. The project I'm working on now requires the next level of SQL (specifically SQL Server 2005) knowledge. That is, I need to know techniques for optimizing the schema, writing optimized queries and even some information about replication and mirroring. Is there a book that anyone here would recommend for that level of expertise as it pertains to SQL in general or SQL Server specifically?
Louis Davidson's book is very good, I interviewed him a while back here: Interview With SQL Server MVP Louis Davidson: Author Of Pro SQL Server 2005 Database Design and Optimization
Or take a look at this: Review of Inside Microsoft SQL Server 2005 Query Tuning and Optimization This one is more centered on tuning the queries itself
Non-MSSQL specific, but an absolute must nonetheless: SQL for Smarties.
I also suggest checking out Itzik Ben-Gan's "Inside Microsoft SQL Server 2005: T-SQL Querying" and its sequel, "Inside Microsoft SQL Server 2005: T-SQL Programming". They cover advanced T-SQL querying, query tuning, and programming in SQL Server 2005.
The Guru's Guide books have quite a lot of material in them including sections covering query plans and tuning. For the next level (essentially understanding how the system works) the third book in this series is quite good. It is mostly a dissection of the architecture of SQL Server 2000.
I totally agree with Phillip Wells, the books from Itzik Ben-Gans covers advanced T-SQL and gives you some really useful tricks.
Another source for advanced T-SQL is the community www.sqlservercentral.com where you can find some free ebooks with the "best of sqlservercentral". And in this community you can test your knowledge in the "question of the day" section.
Sorry for my recommendation to another forum, but i think it is a good complement to stackoverflow and serverfault