SQL

I liked Sam's Teach Yourself SQL in 10 Minutes as a book. It will take you more than 10 minutes though. Gives you the basics and helps solve some early problems. Anything more advanced I use Google or Stack Overflow forums.
 


Morning all

I need to start teaching myself how to query a SQL database for my role at work. I don't need to be advanced straight away but to be able to query a few tables and lookup tables between 2 dates etc. Can anyone recommend a decent book to get me started please?

Cheers
Can you not just copy and paste into excel?!
 
The basics aren't really very difficult at all.

Learn the various forms of SELECT, how to GROUP and ORDER things and if you have a large database, ensure you know about the different types of JOIN and with that you should be able to do most queries.

As stated above, there is plenty of advice online, so you really shouldn't need a physical book these days.

I don't know what platform or type of SQL you are using, but many query packages will let you assemble your query with a point and click type approach, and actually build up the SQL syntax so you can see how they get the result.
 
I'm not sure how clued up you are on databases but you might want to learn a little bit how they work before going into to SQL.

Especially the different types of keys and relationships. It makes SQL much easier in the long term especially with JOINS and stuff like that.

SQL can very easy but if the database is done badly ie. trying to be clever and not using ID's for primary keys or many to many relationships it can become a bit of a chore.

Also if your doing it for something in production then you might want to learn what the n + 1 problem is as it's important unless you want to crash the server.
 
Last edited:
The basics aren't really very difficult at all.

Learn the various forms of SELECT, how to GROUP and ORDER things and if you have a large database, ensure you know about the different types of JOIN and with that you should be able to do most queries.

As stated above, there is plenty of advice online, so you really shouldn't need a physical book these days.

I don't know what platform or type of SQL you are using, but many query packages will let you assemble your query with a point and click type approach, and actually build up the SQL syntax so you can see how they get the result.
Also JOIN. I’ve seen so many people who query one table, stuff the results in an array, then make another SQL query for every item in the array. A join does it in a single line. Or using things like LEFT JOIN can find all items in one table but not the other.
 
Also JOIN. I’ve seen so many people who query one table, stuff the results in an array, then make another SQL query for every item in the array. A join does it in a single line. Or using things like LEFT JOIN can find all items in one table but not the other.

This isn't particularly good advice mind as there's cases where a join isn't the best way to do stuff and what you've said is the best way for it to be done (but you should use eager loading instead).

Stuff like this forum for example. Which will have a thread table, a posts table and then a likes table. Merging them all together in one query would push the work that would usually done by MySQL onto the server instead, splitting it back up etc which is much slower and uses more memory.
 

Back
Top