While writing an application of mine, I realized I was being silly by querying the database several times in some functions. I know I can just pack everything into a single query, and wind up with this nice dict of all the information that function needs. So I set out to accomplish this in a function where a user can share his uploaded files with other users of my application. But I was instantly stuck. I asked this question and came up with a hack solution myself. I wish I was more proficient at SQL, and that I could write it with the same speed and knowledge that I do other programming languages that I use.
So I ask, what are some tips at becoming an SQL writing guru? I find that, for every problem I have, I just google that problem, and maybe get a solution that doesn't work for my particular DBMS (currently I'm using sqlite3, since it's out-of-the-box with Python).
I'm curious about all the treasures in SQL that a beginner might not even know exists. What books should I read? Are there any invaluable online resources for becoming awesome at writing SQL? Any that go through a variety of DBMSs? I want to know which features of SQL to use in which situations, which ones are more efficient, etc.