SQL or Structured Query Language is becoming essential for marketers working for start ups. It’s an easy way to control data
Two great reasons why learning SQL is a great idea according to Udemy.:
- Learning SQL has literally DOUBLED or TRIPLED the speed at which our marketing team can learn & execute.
- We don’t just learn faster. We learn cooler, more interesting shit.
SQL is all simple stuff once you get the hang of it. Check out these top ten most helpful SQL queries :
1. SELECT * FROM stuff;
This query grabs everything from the table and returns it. If you’re not careful with this query, you could find yourself paging through a long list of results.
2. SELECT COUNT(1) FROM stuff;
Here, the query gets just the number of rows in the table stuff. It’s useful if you have a lot of rows, and just want to make sure there is data there without filling your screen.
3. INSERT INTO stuff (name, age) VALUES (‘alan’, 28);
Inserting more data into a table is as easy as running this query. Specify the columns in the order you want to put the data in after the table name (like (name, age)) and then values you want after VALUES.
4. DELETE FROM stuff WHERE name = ‘alan’;
Deleting is as easy as specifying the WHERE-clause that you want to delete. It’s usually best to run SELECT * FROM stuff WHERE name = ‘alan’; first, to make sure you know what you’re deleting.
You can also use !=, <, >, <=, >= in a WHERE-clause.
5. UPDATE stuff SET age = 30 WHERE name = ‘alan’;
This updates alan‘s age to be 30 using the WHERE-clause. You can also change multiple items like UPDATE stuff SET age = 30, name = ‘george’ WHERE name = ‘alan’;
6. SELECT * FROM stuff WHERE name LIKE ‘%rg%’;
You can use this query to do a wildcard match on a column. In this example, it looks for any row that has rg in the column (like in george).
7. AND and OR
If you want to combine multiple WHERE-clauses together, just use AND and OR. You can run a query like this: SELECT * FROM stuff WHERE (name LIKE ‘%rg%’) AND (age > 25);
Placing parentheses around each item you are ‘ANDing’ or ‘ORing’ together is a good best practice.
8. SELECT name FROM stuff where age > 25;
With this query, you can select just one column — the name-column in this example. You can also grab two columns, with SELECT name, age FROM stuff where age > 25;
You can also rename columns: SELECT name AS n FROM stuff;
9. SQLite3: .schema stuff
PostgreSQL: \d stuff
MySQL: describe stuff;
If you need to discover the schema of the database — what columns it contains — you’ll need to use different queries, depending on which database engine you’re using.
10. EXPLAIN SELECT * FROM stuff;
This is an advanced query. It’s particularly useful if you need to figure out why a query is so slow.
You can use EXPLAIN before a SQL statement (or some variant), and it will break down the timings of the various parts of the query. It’s useful for debugging why a complicated query is slow. You can dig even deeper, depending on what database engine you’re using:
- In PostgreSQL, you can use EXPLAIN and EXPLAIN ANALYZE before your query. The Beginner’s Guide to PostgreSQL can quide you through the process.
- In MySQL, you can use EXPLAIN before your query. MySQL Database for Beginners is a good starting point.
- In SQLite3, you can use EXPLAIN QUERY PLAN before your query. To learn more, try Introduction to SQL Training.
This is really easy to learn too. If you want to learn just go to:
I’m in the middle of lessons right now and if I can do it, anyone can do it. It’s FREE to sign up and it’s simple.
This is their simple layout for their lesson guide.
And this is their lessons. You watch videos and take notes on the side. Super easy right?
Just visit https://www.udemy.com/mysql-database-for-beginners2/#dashboard to learn how.