## SQL Statement Fundamentals: The COUNT Function

Hello, hello, hello SQL fans! (Or gracious friends and family perusing the site. 🙂 ) The journey into learning SQL continues, and today we’ll cover the COUNT function. Jumping right into it, here’s our working definition of the SQL COUNT function:

The COUNT function should return the number of input rows that match a specific condition of a query.

Rather, this would appear to work similarly in concept to the COUNTIF(s) formula(s) in Excel.

# COUNT Statement Syntax Examples

Here’s what a simple COUNT SQL statement might look like:

## 1. Basic COUNT (*) FROM SQL Statement

SELECT COUNT (*) FROM table;

Breaking it down a bit, the COUNT () function returns the number of rows returned by a SELECT clause. When you apply the COUNT () statement to the entire table, pgAdmin/PostgreSQL will scan the entire table in a sequential manner.

## 2. COUNT (column) FROM SQL Statement

SELECT COUNT(column) FROM table;

Similar to the COUNT(*) function, the COUNT(column) function returns the number of rows returned by a SELECT clause. However, if you have empty or NULL values, the COUNT function will not take those into account.

## 3. COUNT (DISTINCT column) FROM SQL Statement

If we do a bit of application from our past learnings, we can make a COUNT with DISTINCT SQL statement:

SELECT COUNT(DISTINCT column) FROM table;

# Applying the COUNT SQL Function

Alright, so let’s work our way toward applying what we’ve learned. To start, let’s do the traditional probe of the table before diving in, to familiarize ourselves. Below, we’ve done a basic,

As we get familiar with the table, we can scroll down and see this particular table has 605 rows in it. This will be a reference point as we continue.

Moving forward, we’ll execute a basic SELECT COUNT (*) FROM address; SQL query. Below, you’ll see a slightly different result was returned. Inst3ead of 605 rows, 603 was returned. At this point, kindly reference our note about empty / NULL  values being excluded from the COUNT function.

We’ve established a general proof of concept for the SELECT COUNT statement, considering the reduced load on the server and yourself, for a quick count. Let’s now try calling specific columns. In our first exploration of the address table, we saw a number of columns, including the district. Let’s say we want to get a count for how many districts/states our customer base covers.

Above, a count of 378 distinct district values has been returned. Wow, what coverage!

A quick aside for future usage, you can also nest the column reference in its own set of parentheses, as shown and returned below.

# Wrap-Up

There you have it! We’ve learned a bit about the COUNT function, what it does and how to use it. It will likely come in handy for future articles, particularly when we delve into group-by excercises. If you missed it, here’s the previous article on learning how to use SELECT WHERE and another recent article on learning how to use SELECT DISTINCT. Also, to start from the beginning, here’s my running list of articles on how to learn SQL. Cheers!

## SQL Query Fundamentals: SELECT WHERE

Welcome back, travelers! The journey continues in learning SQL. In case you missed it, the past couple of posts were learning to use SELECT DISTINCT and Restoring an SQL database with table schema only.

Today we’re going to learn about using the SELECT clause with the WHERE statement for essential SQL queries.

# A Quick Recap, or, Why SELECT WHERE is Important

As previously mentioned, we’ve covered a range of beginning SQL topics. Mainly, we’ve learned about using the SELECT statement to query all (*) or query specific columns of data from a table. Because we’ve been working with a pared down table with only a few hundred rows, it’s not a problem in this “academic” setting to return all the rows. But what if we’re working in a larger database? A recent keyword research dataset 75,000 rows long comes to mind. (Though I would imagine that too, would be a small dataset in the grand scheme of things, but I digress.)

When we start working with larger databases, granularity will become vitally important. This is where (pun not intended) the SELECT WHERE statement comes in.

# Sample Syntax of the SELECT WHERE Statement

With proof of concept in mind, let’s jump into it headlong. Below is a syntax example, demonstrating what a SELECT WHERE SQL query might look like.

SELECT column_1,column_2

FROM table_name

WHERE condition1;

The SELECT statement is old news to you adventurers that have been following along. The WHERE portion of this query will be the power in this article.

# More About the SELECT WHERE SQL Statement

The WHERE clause appears right after the FROM clause of the SELECT statement. The conditions listed within the WHERE clause are used to filter the rows returned from the SELECT statement. Because we’re working in pgAdmin / PostgreSQL, we’ll have available standard operators to construct the conditions. Better still, some (or most) of the operators we’ll look at are fairly universal, so these operators should work in MySQL, Microsoft SQL, Amazon Redshift, etc.

# List of SELECT WHERE Operators

Below is a list of common SELECT WHERE operators. Again, most of these should be fairly universal, regardless of the SQL database management program you’re using.

 Operator Description = Equal to > Greater than < Less than >= Greater than or equal to <= Less than or equal to <> or != Not equal to AND Logical operator AND OR Logical operator OR

Plugging this back into SQL statements, we’ll be using the operators on the left to filter down and return only specific rows in our queries.

# Sample SELECT WHERE Statements

Let’s  cover some guiding examples that will help us apply the SELECT WHERE operators. To start, we’ll kill two birds with one stone: jogging the memory by utilizing a previous query and exploring the table we’ll be querying. Below, we’ll be a bit naughty by calling on all columns from the table.

SELECT * FROM customer;

Above, we’ll see our results and some candidate columns to query the heck out of. Let’s keep moving.

## Example 1: The Basic SELECT WHERE Statement with 1 Condition, Returning Only Customers with a Certain Name

Okay, let’s say that we want to only return customers of a certain name, say, “James”. The SELECT WHERE statement will help us make quick work of this database need.

SELECT last_name,first_name

FROM customer

WHERE first_name = ‘James’;

If all goes correctly, we should only get back a customer with the first name James. ‘Ello James!

Side note 1: you don’t have to return the columns you’re filtering against. For example, we could return the email column and still filter by name.

## Example 2: A SELECT WHERE Statement Using 2 Conditions, Returning Customers with a Certain First AND Last Name

Perhaps you’ll want to do something more targeted with your data. I know this is a narrow and frankly creepy example of calling out one name, but think maybe of a City/State or Source/Medium pairing? Anyway, with the sample dataset we have, below we use the AND logical operator to combine two conditions into one query.

SELECT last_name,first_name

FROM customer

WHERE first_name = ‘Jared’ AND last_name = ‘Ely’;

If executed properly against this particular sample dataset, we should be returned only the values for one fictional Mr. Jared Ely.

Quick side note 2: that we should have mentioned sooner: we’re using single quotes here because the values we’re querying against are string values. As such, the single quotes help us match format, et cetera.

## Example 3: Another SELECT WHERE Statement Using 2 Conditions, Returning Customer ID’s where payment was in certain dollar amount ranges

Let’s say we are trying to identify a range of customers in our database. In this third example, we want to query Customer ID’s and names in a certain range. We could think of it as a feeble attempt to get our first customers or our most recent customers for a special email flight. Below, we’ll exercise the OR operator to accomplish our desired output.

SELECT customer_id,first_name,last_name

FROM customer

WHERE customer_id <= 2 OR customer_id >=20 ;

# Understanding the Subtle Differences Between AND / OR

Quick note about differences between the AND / OR operators. If you’re trying to filter data from two different columns, then AND is your filter. If you’re trying to get distinct values within a single column, then the OR operator will be best suited for the job.

# Wrap-Up

What a world of possibilities we’ve opened! I found myself needing to slow down and pay more attention to detail in this area of learning. The nuances of selecting certain columns but filtering by others when practicing threw me for a loop once or twice.

Thanks for joining, in the next article, I’ll be covering some introductory material around the COUNT function. In the meantime, check  out our running list of posts on how to learn SQL.

# Introducing the SELECT DISTINCT SQL Statement

Alright, welcome back to our journey with SQL! If you’re just tuning in, we:

In this article, we delve slightly deeper into SQL queries, with the consideration that SQL databases and tables can have a lot of duplicate data, and you might not always want that duplication! This is where today’s subject comes in: using the SELECT clause with the DISTINCT keyword.

Sometimes when you’re managing a database or table, you only want unique (distinct) values when executing SQL queries. Thus, you can get around a large number of duplicate values using the DISTINCT keyword.

# The Basic SELECT DISTINCT Syntax

Here’s the general format of what a SELECT DISTINCT query might look like:

SELECT DISTINCT column_1,column_2  FROM table_name;

Next, we’ll take a look a very simplistic example of why you might want to only pull unique values from a database.

# Why Use the DISTINCT Keyword?

So we’ve generally been working from a popular public SQL “sample” or “sandbox” database that deals with DVD rentals. In one of the tables, “film”, there are a number of columns containing a wide range of information. For example, we can see below querying the release_year column of the film table, a few films were released in 2006. If we’re looking for a unique list, this is not a good start!

# Using the SELECT DISTINCT Query in pgAdmin

Working off our example above, we want to see if 2006 is the only release year. To accomplish this, let’s try the below query:

SELECT DISTINCT release_year FROM film;

Below, the query in action through pgAdmin, after hitting F5 to execute and refresh. We can see 2006 is the only unique release year in this table. Zoinks!

Let’s try another example. Perhaps we’re interested in gathering pricing information for some revenue forecasting and analysis. Below is a query we would use to get the distinct rental prices from the film table:

SELECT DISTINCT rental_rate FROM film;

We see that there are only 3 price points in this table. What fun in simplicity!

# Wrap-Up

Thanks for joining! Next post, we’ll be looking at the SELECT WHERE statement. Check the SQL learning & education page for a running list of articles. Cheers!

# Getting Started in SQL Statement Fundamentals

Howdy, all, welcome back to our journey learning SQL. This post will deal with basic SQL statements. In fact, most of these SQL statements should be applicable to most major types of SQL databases (MySQL, Oracle, and so forth.)

# The SELECT Statement (or Clause)

First up, we’ll start with the “Hello World” of SQL: SELECT. We’ll look at the formal conventions of the SELECT statement and some examples using the statement. A quick aside: SELECT is also often known as a clause in SQL settings. For the purpose of this article, the educational materials I’m walking through proposes clause and statement may be used interchangeably for these purposes.

SELECT is one of the most common tasks in querying data tables with SQL. Further, it has many clauses that may be combined to form a powerful query. Let’s look at the basic form of a SELECT statement. Below, you will use the SELECT statement to call in a column or some column names, separated by a comma if multiple columns, then FROM a table.

SELECT column1,column2,column3 FROM table_name;

So, breaking down again the select statement.

1. Specify a list of columns in the table which you want to query via the SELECT clause
2. Use a comma between each column you are querying, if multiple columns
1. If you want to query all columns in a data, save yourself some time by using the * asterisk wildcard as a shortcut for selecting all columns
3. After you’ve called in the appropriate columns in the SELECT clause, follow it with FROM, where you indicate the appropriate table name

# Sidebar 1: Random facts about the SELECT statement and SQL language

Time for a TV timeout! Did you know that that the SQL language is case insensitive? So if you use “SELECT” or “select”, you should get the same results. For the purposes of this education and sharing, SQL clauses / keywords / statements will be typed in all uppercase caps to make the code easier to read and stand out among all this text. 🙂

Okay, just one more sidebar note! It’s generally not encouraged to use the asterisk (*) select all columns wildcard in queries. Why? If you have a robust table with a ton of columns and a great depth of data beneath those columns, you could be placing unnecessary load on yourself, the SQL server and the SQL application (pgAdmin / PostgreSQL).

# Application Example 1 for the SELECT Statement

Let’s jump into executing actual SQL commands against databases in pgAdmin!

Below, I’m going to open the file tree, select “dvdrental”, then click “Tools” in the top menu, and select “Query Tool” to execute arbitrary SQL queries and statements.

You should then see the screen below if you are in pgAdmin 4. If you are in pgAdmin 3, then it should appear as a new window.

Let’s have some fun, why not go against our own advice and query a whole table? Below, you can see in the query window, we’ve typed:

SELECT * FROM actor;

Into layman’s terms from above, we’re selecting (SELECT) all columns (*) from (FROM) table actor (actor).

Important: My image example doesn’t show it below, please, put a semicolon at the end of the line! (I got hasty making screen shots. 🙂 )

After you’ve typed the query, go to the lightning bolt above the window, and click “Execute/Refresh”. I’m just going to punch F5, because I’m about that keyboard shortcut life. In the future, I’ll likely introduce a command or action, note its keyboard shortcut and use that shortcut moving forward for any other examples.

The query should run and refresh. I now have a new tab in pgAdmin, with data output returned from my query. Let’s take a look below.

Okay, so we’ve got four columns returned: actor_id, first_name, last_name, and a last_updated. You’ll also note that below the column names are quick descriptions of the data type for each column. And of course, we see our beloved celebrity data returned below, all 200 rows.

Let’s examine further the data types listed below each column name. The integer below actor_id is pretty simple, numbers. Next, the character varying, below first_name and last_name. Character varying is essentially just string text. The (45) denotes the limit on character count length. Last, the timestame with YYYY-MM-DD and military style HH:MM:SS.XX time, without time zone. We won’t worry too much about the timestamp for now.

If you’re somewhat knowledgeable in SQL, you may rightly decry our glossing over of data types. For beginners, data types will be covered in more detail later. Data types will become increasingly important later, as we execute statements such as, WHERE, in which data types make or break the query. Promise, we’ll cover data types in more detail later.

# Application Example 2 for the SELECT Statement

So we kind of broke our rules in the first SELECT statement SQL query example. However, some rules were made to be bent or broken, yes? In this example, we’ll follow best practices a bit more closely and select a column or columns by name from a table within the dvdrental database.

Remembering our SELECT column1,column2,column3 FROM table_name format, consider the below, and see it typed in (with closing semicolon on the statement!

SELECT first_name,last_name FROM actor;

Before we execute and refresh via F5, please note that I’ve not included spaces between the column names and comma in the statement. Alright, below is what we see when we execute and refresh.

In our screen shot, we see at bottom right, confirmation of the query execution. In the output window, we’ll only see what was queried: first_name, last_name. So we’ve left out the actor_id and last_updated columns.

One more note on our output, you’ll notice that all 200 rows were returned for this query. If you think about enterprise level data, that could be 200 million rows, zoinks! As we progress through our material, we’ll look at the aforementioned WHERE statements and other conditions / methods to limit or control the rows in query output.

# Perfect Practice Makes Perfect

For the educational benefit, we’ll reinforce and apply what we’ve learned one more time. Let’s say that we’re a business and marketing analyst back in time when DVDs were still used (it’s okay to laugh!) We need to send a New Year’s promotional email (It’s January 2017 when this post was originally published) to all existing customers. We’re going to build and execute a query to that effect.

Below, you can see we’re still in the dvdrental database, in the arbitrary query code input window, with statement: SELECT first_name,last_name,email FROM customer;

One last quick note on syntax and formatting: you can go multi-line! In the below screenshot, we have typed the same query, but added formatting. Explained: SQL will read your code as one line until it runs into the closing semi-colon (;). A common practice is that for every keyword, a new line is created in the query. (Of course, the statement is not closed via semi-colon until appropriate.) I’ve also taken one more step below from various ranging coding practices (CSS, C++, etc.) and indented the ongoing portion of the query to help visually break up the code a bit.

# Wrap-Up

Woohoo, we did it! We ran our first basic SQL queries in pgAdmin / PostgreSQL. We learned how to select all columns within a table and select separate desired columns within a table. Be sure to re-visit my other articles on learning SQL, visit the previous article on restoring an SQL database with table schema only.

In our next post, we’ll learn about using a SELECT DISTINCT statement.

## Restoring a SQL Database with Table Schema Only in pgAdmin x PostgreSQL

Howdy! Welcome back to our shared journey of learning SQL. Last time, we learned about creating, deleting and completely restoring SQL databases in pgAdmin. Today, we’ll learn about how to restore a database, but only its table schema.

Specifically, we’ll restore the table names and preferences for types of data within those tables. However, the actual data itself won’t be ported in.

Think of it as taking your house or apartment, and recreating, but you don’t move in with the furniture. (Maybe a sibling instead? 🙂 ) According to the material I’m working through, this method of database restoration is very common and is something we should have down pat.

# Database Table Schema-Only Restoration, Method 1

An easy method to start this is to right click on the Databases header near the top of the file tree, and to select “Create” > “Database”. With a fresh new database, we’ll have flexibility to do some more management on the “front” side of things. (Knowing I may be abusing terminology a bit, but makes sense to me while writing this.)

For this example, I’ve finished the new database creation by naming (“OnlySchema”) and saving a new database. Below, you can see the new database in the file tree. Also, if we click through the tree as such, “Schemas” > “public” > “Tables”, we’ll notice there are no tables! (Compare that path exploration to the dvdrental database tables, where you can find 15 tables.)

Anyway, let’s get on with restoring table schema only!

1. Right click on “OnlySchema” and select “Restore”
2. Select the “Custom or tar” option for the Format field
3. Select the file via the dialogue, or paste in your file path
• Up to this point, you should notice we’ve taken the exact same steps for a full database restore. However, #4 is where things are slightly different. Pay attention!
4. As shown below, click “Restore Options”, and activate the radio button for “Only schema” to yes
5. Click “Restore” and refresh!

After the refresh, we should see something like below, where if we select the tables option and view “Properties”, we’ll see 15 empty named tables.

# Method 2: Schema-Only Restoration onto a Database with existing tables, data

What if we’re working with a database that contains existing tables and data? And suppose we need to restore only the schema? Perhaps an error was committed in formatting / management and must be corrected.

Fortunately, this method of restoration is extremely similar to Method 1. For this scenario, there’s one added step toward the end:

1. Right click on “OnlySchema” and select “Restore”
2. Select the “Custom or tar” option for the Format field
3. Select the file via the dialogue, or paste in your file path
4. Click “Restore Options”, and activate the radio button for “Only schema” to yes
• Here’s our jump off point, the next step is what differs from Method 1.
5. Scroll down the dialogue box slightly. You should see a field and radio button for “Clean before restore”. Activate the radio button to “Yes”
6. Click “Restore” and refresh!

After running the restore job and refreshing, we can verify the Schema Only and data clean prior to restoration occurred correctly. Below, we can click through the file tree down from “dvdrental” > “Schemas” > “public” > “Tables” and check the table properties to see that there are zero (0) rows of data.

# Wrap Up

I do hope these articles are serving a useful introduction to navigating pgAdmin, and getting familar with the foundations of PostgreSQL and databases. In the forthcoming articles, we’ll start learning about basic SQL syntax. To keep track of all the shared SQL posts and learnings, visit the SQL Education page for a list of articles to date. Cheers!

## Creating, Restoring and Deleting SQL Databases with pgAdmin 4

Howdy! Let’s continue the journey into learning Structured Query Language (or SQL). Previously, I shared my notes on the absolute beginning point for starting SQL, and also getting started with PostgreSQl and pgAdmin.
Now, we venture into some basics of database management via SQL:
• Creating a database with pgAdmin
• Restoring a database with SQL commands
• Deleting a database

# Creating a new SQL Database in pgAdmin via Graphical User Interface

So, let’s retrace our steps on creating a new database. After you’ve successfully started pgAdmin and accessed your databases, right click “Databases” and go to “Create” > “Database”. Then choose your desired name and save.

Give it a second, and your brand spankin’ new database should be created! (Alternate method, you could select the “postgres” database in the file tree and select the option to create a new, arbitrary SQL query. In the Query window, type:

CREATE DATABASE dvdtwo;

If you run and refresh you should see the output of the code’s successful run, with no results, and a new database in the file tree. Joy!

# Deleting (Dropping) Databases in pgAdmin

Let’s build some character and delete the database we just created! Fortunately, deleting (also known as dropping a table is super simple in pgAdmin / PostgreSQL. Below, in the interface, we right click the name of the newly created database and click “Delete/Drop”, and click Okay. Obviously, be sure you don’t do this accidentally.

# Gracefully Restoring a Database

In the second SQL article, we previously restored a database. We’ll revisit that process in the pgAdmin interface again here. Practice, practice, practice! Let’s restore the dvdtwo database created earlier in this article for good practice. Below, we’ll right click the “dvdtwo” tree header and select the “Restore” option.

In the resulting dialogue box, I attempted to use the interface’s file browser. However, I was met with some bugs/error messages. Thus, I copied the file path from Windows Explorer, pasted it into the file path name field and began the restore job. It took a few moments to run, then I refreshed the database and saw tables populated under dvdtwo > Schemas > public > tables. Hooray!

# Wrap-Up

Thanks for tuning in! Next article, I’ll share my learnings for restoring a database, but with only the table schema. So to be more specific, I’ll restore the framing and architecture of the sample database, but without the data. This seems a bit like copying and duplicating sheets in Excel, but with blanks for data, so you can populate at your discretion. See you soon.

PS- If you’re just arriving at this article, here’s my running list of articles that detail how to learn SQL.

## Introduction

Welcome back to the grand SQL journey! If you missed the beginning, here’s my previous post as a complete beginner to SQL. In this post, you will:

• Become familiar with the program and some of its release history and
• Walk through an installation of pgAdmin.

According to the educational material I’m working through, it’s commonplace (in some circles) to use a graphical user interface (GUI) when working with a SQL engine. (Compared to working with command line, zoinks!) That being said, pgAdmin is reportedly one of the most popular interfaces for PostgreSQL, the SQL engine / platform of choice listed out in the previous post. For the purposes of our education, I’ll be working in pg Admin 4.

## Installation of PostgreSQL and pgAdmin

Here are the steps:

• Install PostgreSQL and pgAdmin through their default Windows install methods. (Sorry Mac and Linux users, this party is PC only for now!)
• Use the .tar file to restore a database we’ll be working with

First, head to https://www.postgresql.org/ in a new tab or window. When you’ve arrived, you should see something like the below screen, and click the “Download” link in the navigation.

After arriving at the Download page, you should see the below. Under the “Binary Packages” for pre-built packages, select your appropriate operating system. Windows is shown below for the purposes of this demonstration. If you feel led or qualified to choose the source code option, you probably don’t need to be reading this article anyway. 🙂

Following the Windows link should take you to the Windows Installers page.  Under “Interactive installer by EnterpriseDB, click the “Download the installer” link. Another option for “Graphical installer by BigSQL” exists, but there have been some anecdotes of annoyances with the BigSQL experience.

Clicking on the link illustrated above should take you to the EnterpriseDB site, where a screen like the below should appear. When you first arrive, you will be prompted to select a version of PostgreSQL and your machine’s operating system details. Below, I’ve selected PostgreSQL 9.6.1 and Windows x86-32, because I’ve got a really old laptop! A quick note on the PostgreSQL version selection, you should choose the latest non-Beta version to install. As this post regards software and tech, it could quickly become outdated. When you have selected the appropriate details, click the ever-important “DOWNLOAD NOW” button.

After the .exe file downloads, open it, allow it to run. A screen for Microsoft Visual C++ Redistributable will likely appear, let it run and complete. Next, the PostgreSQL installation dialogue should appear. (Below.)

Accept the default installation and data directories, unless you have a weird and specific reason to do something else. After you do this, enter your desired password.

A quick and necessary aside. Please follow best practices for passwords and information security. It is your sole responsibility to do so: protecting your information and yourself. I accept neither liability nor responsibility, nor in whole, nor in part, for your password security. Be smart.

Okay, with that out of the way, proceed to the Port portion of Setup. Accept the default and proceed. After the port screen comes a locale configuration. Accept the default and proceed. Now, you should be to start the installation process. Click “Next >”!

Once you click install, you should see a pretty traditional installation progress screen that creates a ton of directories, unpacks HTML files, and so on. (Note: this took my machine 5 minutes or so to install.) If you care to do so, uncheck any mail subscription offers and finish the installation!

From here, you should be able to get to pgAdmin 4 from your Windows start menu. Tah-dah!

If you expand the servers icon, you ought to see something along the lines of PostgreSQL9.6. If you click to expand the PostgreSQL 9.6 item, you should be prompted to enter your password. From there, you should see a dashboard with some various charts becoming populated, like below.

Next, a sample database will be restored. As shown below, please right click “Databases”, then mouse over the menu item “Create” and click “Database”.

From there, name your database and save it! Once it’s successfully created, you should see a new part of the tree for your database, with options underneath such as Casts, Catalogs, Event Triggers, Extensions and so on.

To restore data into the database, right click the database name and select the restore option. First time users, you may see a dialogue box saying, “Configuration Required”. No worries here, we’ll get through that momentarily. Click File > Preferences > Paths > Binary Paths.

Once you’ve reached the point as described and shown above, you’ll need to open a new Explorer window. (Sorry, Mac and Linux folks, no guidance from me here.) Go to Computer > Program Files > PostgreSQL > 9.6 > bin. Copy the address and paste into the pgAdmin PostgreSQL Binary Path, click OK.

That should now allow you to restore a database. Now return to the above steps, and when you select restore, select the options as desired. You should see a processing dialogue and success message. When this is complete, right click the database name and select “Refresh”. Very important – think of like you needing to refresh the data sources when working with pivot tables in Microsoft Excel.

Okay, you should have your first database! right click the database name and select “Query Tool”. Let’s make our first SQL query FTW!

In the code window, type:

;

Then, either select the lightning bolt and execute + refresh. Or, you could just press F5 and it accomplishes the same thing. If the query is successful and you didn’t misspell a simple table name like I did the first time, then you should see the table in the Data Output window.

## Wrap-Up

Alrighty! How about a rip-roaring start into SQL? Excited to keep learning with you. Stay tuned. If you’re just arriving at this article, here’s my running list of articles that detail how to learn SQL.

# What is this?

To be honest, I haven’t done much blogging or writing lately. Life (read: work) happens, and it gets busy. However, I’m feeling invigorated with a strong desire to expand my horizons. One such manifestation (snooze, I know) of this is to learn a bunch of new things, for where technology and industry are headed.

Thus, I present to you, learnings on SQL from a course I’m taking! Frankly, this should be boring to a majority of people. However, this is a way of self-accountability, and sharing what I learn along the way about Structured Query Language (SQL) programming, and hopefully how it applies to a bunch of awesome things! If you haven’t bounced already, here we go.

# Square 0: What are Databases?

As the title/URL describes, I’m starting from an absolute beginning. While I have a range of experience (or lack thereof in some cases) with HTML, CSS, JavaScript, PHP, Regex, etc., I am completely new to SQL. That said, this isn’t square 1, but square 0.

Databases are systems that allow users to organize and store large amounts of data. Databases can have a wide variety of users and use cases. Potential database / SQL users include analysts in marketing, business or sales. Additionally, technically-focused personnel such as data scientists, software engineers and web developers may also use databases for a range of purposes.

# Discussing the Transition from Spreadsheets to Databases

Many practitioners in business have some familiarity with a spreadsheet program, such as Microsoft Excel, Google Sheets or Open Office.

Spreadsheets are often useful for a one-time analysis piece or quick charting, particularly with small data set sizes. Additionally, usage of a spreadsheet program ensures that a wide range of folks with varying expertise can access, use and manage the spreadsheet data.

So where do databases come in? Databases are great for ensuring data integrity and/or handling large & robust data sets/ Databases are also great for use cases where you need to quickly merge different data sets or automate actions with your data for frequent usage or re-use. Additionally, databases are widely used in powering websites and other applications.

In summary, the transition from spreadsheet to data comes when you bring massive amounts of data to life! The hope of the educational materials are that institutional knowledge in spreadsheets can be leveraged to help understand and master SQL database usage.

What are some quick hacks to translating spreadsheets to databases? The first is that tabs of a spreadsheet can be set equal in your mind to tables. Within each table is contained a set of rows, and a set of columns.

## What are some of the top SQL database / data warehouse platforms options?

For your enlightenment and education, below are some common SQL database and data warehouse platforms.

• Postgre SQL (Preferred for example use: free and open source, widely used on the internet, multi-OS)
• Amazon Redshift data warehouse
• MariaSQL
• Microsoft Access
• Microsoft SQL Server (MS SQL Server Express)
• MySQL
• Oracle Database
• SQLite

In addition to straight database programs and data warehouses, there a range of other programs that utilize the SQL programming language for core functions. Below is a short (and rather incomplete list) of other popular SQL applications and uses.

### Other Applications of SQL

• Looker
• MemSQL
• Periscope Data
• Hive (On top of Hadoop)

# A Bit More About SQL

SQL stands for Structured Query Language. It can be applied in a wide range of manners, including PostGreSQL that will be used in these examples. Further, SQL is the programming language that will be used to communicate with databases in this experience.

To start, a sample SQL statement:

SELECT customer_id, first_name, last_name

FROM sales

ORDER BY first_name

# Review

Here’s a quick overview of what I learned, and have consequently shared.

• What’s a database?
• How is a database different from a spreadsheet?
• Why should a database be used?
• What are some database / data warehouse platforms that operate with SQL?

If you’re just arriving at this article, here’s my running list of articles that detail how to learn SQL.

# Upcoming Educational Material on SQL

• PostgreSQL Installation
• Databases and Tables Basics
• SQL Syntax and Statement Fundamentals
• GROUP BY Clause

• JOINS