Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Can anybody show me how to learn SQL? Please.  (Read 1094 times)

Transcendant

  • Bay Watcher
    • View Profile
Can anybody show me how to learn SQL? Please.
« on: April 17, 2016, 02:20:27 pm »

I would like to learn SQL to expand my excel skills. I think it would help me out a lot. I also bet I'm not alone in this.

Does anyone here know SQL? Know how they learned it? How I and others like me here can?
Logged

Antioch

  • Bay Watcher
    • View Profile
Logged
You finish ripping the human corpse of Sigmund into pieces.
This raw flesh tastes delicious!

ancistrus

  • Bay Watcher
    • View Profile
Re: Can anybody show me how to learn SQL? Please.
« Reply #2 on: April 17, 2016, 06:21:24 pm »

http://www.sql-ex.ru/
Sort of like project euler for sql, this site has hundreds of exercises sorted from the most primitive to ridiculously difficult. Yes, you would need to register, but it is worth it.
The early exercises include hints and links to a manual that explains basic concepts, techniques and tricks. Each exercise has a section on the forum where users post their solutions.

Cons: It won't teach you anything about databases that is not directly related to select/update/insert/delete statements. Nothing about views, triggers, sequences, etc.
Logged

nenjin

  • Bay Watcher
  • Inscrubtable Exhortations of the Soul
    • View Profile
Re: Can anybody show me how to learn SQL? Please.
« Reply #3 on: April 17, 2016, 08:31:08 pm »

I recommend getting a good database browser like SQLYOG Community. It's free, and what I use at work. I hide/abstracts some statements from you but it has a lot of useful tools and is fairly easy to learn. I find it easier to grok everything when I can have it laid out visually.
Logged
Cautivo del Milagro seamos, Penitente.
Quote from: Viktor Frankl
When we are no longer able to change a situation, we are challenged to change ourselves.
Quote from: Sindain
Its kinda silly to complain that a friendly NPC isn't a well designed boss fight.
Quote from: Eric Blank
How will I cheese now assholes?
Quote from: MrRoboto75
Always spaghetti, never forghetti

nenjin

  • Bay Watcher
  • Inscrubtable Exhortations of the Soul
    • View Profile
Re: Can anybody show me how to learn SQL? Please.
« Reply #4 on: April 18, 2016, 09:54:54 pm »

I guess I can add more here.

I started learning MySQL 4 years ago when I started my job. Up until that point the only language I'd ever worked with was Python and that was on an amateur basis trying to write a text adventure game.

But I was familiar enough with the concept of code that I had a good start.

I've never gotten formal training or schooling in SQL. Everything I know I've had to learn myself or just been told by someone what to do enough times that it stuck.

You need a good introduction to databases though. It sounds funny but I started with this because a guy at work had it laying around.

I don't think I'm particularly smart or clever. In fact I consider myself math stupid. And I'm only familiar with SQL to the degree I can do beginner and intermediate stuff pretty well. But I don't think it's super hard to figure out until you're trying to do complicated things that involve several tables at once, or an elaborate set of operations all contained in one massive query. Manipulating one table (or column or spreadsheet) to do one or two or things is pretty trivial. I.e., can be done with very basic queries.

Learning syntax (where all the characters have to go in your query and in what order everything has to be stated) is the trickiest bit for me, but there are basic constants. Like a complete query always ends with a ;. As far as order of operations goes, it helped me to think of a SQL query in a couple stages.

1. The Select Clause. This is where you say what column(s) you want to see data from.
2. The From Clause. This is where you say what tables you want to pull said columns from.
3. The Where Clause. This is where you qualify your select statement to include/exclude data. (I.e having no Where Clause just gives you all the data you explicitly asked for in the select statement.)

That's the simple structure of a query to find and retrieve information.

Once you figure out how to correctly query for data, you move on to manipulating it in various ways, like:

UPDATE `customer` SET `active` = "False" WHERE `active` = "Unknown"
DELETE * FROM `customer` where `active` = "Pastdue";
INSERT INTO `customer` (the names of the columns)
VALUES (the data that goes into each column);

There's tons of shit you can do between any of those steps (like joining two different tables together to work on the data), before any of the steps (setting variables, aliases, changing the way the table you're dealing with works) or after all the steps (ordering the data result set by some value or setting a limit on the number of results than can be returned. And there's other qualifiers you can add to them (SELECT DISTINCT, INSERT IGNORE, etc...)

When you get deeper, you can start writing functions that are just essentially batched queries you can simply call by name. You can create triggers to do actions when something happens to one of the tables. All sorts of neat stuff.

So I guess in the end...all you really need to start learning SQL is a database to work on, and Google searching the commands that make up your queries.
« Last Edit: April 18, 2016, 10:04:24 pm by nenjin »
Logged
Cautivo del Milagro seamos, Penitente.
Quote from: Viktor Frankl
When we are no longer able to change a situation, we are challenged to change ourselves.
Quote from: Sindain
Its kinda silly to complain that a friendly NPC isn't a well designed boss fight.
Quote from: Eric Blank
How will I cheese now assholes?
Quote from: MrRoboto75
Always spaghetti, never forghetti