SQL #1

For the textbook I’ll be using the O’Reilly publication of ‘Learning SQL’

And I’m also using sqlbolt.com

Before anything, a database itself, is a set of related information. All the information in a database has a common entity it’s referring to.

The Yellow Pages phonebook is a database. But it has some issues:

  1. It only uses first and last names as its identifier. Even if you have other information on the person you’re looking for, if you don’t have their full name, you’re SOL.
  2. It’s physical, so it can easily be outdated since people move or change their number

This is what’s called a manual data system. Any and all organizations who rely on paper file cabinets have a manual data system. So when computers were first being built, this is one o the first problem they wanted to solve. We all know how messy and unreliable paper files can be.

These computers not only helps us store the data, but retrieves it. When I was in college and I had to buy a textbook, I didn’t prefer to read on a screen, but I loved that I was able to use the ‘find’ feature instead of flipping through pages.

Statements

There are 3 types of SQL statements that serve data structures in their own way (I feel like there may be more, but I’ll trust the book for now)

  1. Schema – define
  2. Data – manipulate
  3. Transaction – begin, end, and roll back transactions (not sure what this means yet)

Query

SQL stands for Structured Query Language. A ‘query’ is, by itself, a question. In SQL terms, this question means that I am seeking information.

Every table (still a dataset) has an entity it’s referring to. Each table is made of rows and columns. A row represents the instances of the entity. Columns represent the common properties of those instances.

So if we made a table of players on a certain basketball team. The rows would be the names of the players, hence why this used for instances, because they’re individual and unique; you won’t see the same player listed twice. The columns would be the properties of those players like height, position, field goal percentage, etc. Every player will have their own space in those properties

The basic statement for a query seems to be the ‘SELECT’ command.

So for the imaginary basketball table, if I wanted to view the full table, I’d do

SELECT * FROM bball

‘bball’ is the table’s name in this case. Anytime I want to retrieve something from this table, I have to end the command with its name

Let’s say I want to view a specific column of this table, say the heights. The position of the asterisk we just used (between SELECT and FROM) was where the command specifies the query. So since i want to look at the heights, I’d just replace the asterisk with ‘height’.

SELECT height FROM bball

This would show me only the height column.

And lastly, if I want to view multiple columns, just separate them with a comma. Viewing height and position while leaving out field goal percentage would look like:

SELECT height, position FROM bball

I know this was pretty scattered. I’m brand new to this. We’ll do some more digging tomorrow.

Leave a comment