SQL or Structured Query Language is how you interact with a relational database
SQL is the language
MySQL is the database
Might hear S Q L
Might hear See-quil (or sequel)
The language is used to ask questions of your database
Why it's so popular
SQL is interactive, so you can see your results pretty fast and make sure you're looking at the right info
It's close enough to programming a lot of developers are very comfortable learning it quickly
Because it's popular a lot of people learn and use it, therefore making it more popular
SQL is relatively dependable and has been in use so long a lot of people have done a lot of testing on it
Once it's setup correctly a company is unlikely to move away into a new technology
Because SQL is relatively human readable a lot of people use it in companies including marketing, QA and sales,some larger companies will even offer free courses for people to learn it
SQL the brand
SQL was standardized in the 80s, but there are different dialects depending on what database you're using
SQL server is proprietary and owned by MS, Dialects including PostgreSQL and SQLite
For example PostgreSQL is open source and for Object oriented databases (we've been talking about relational), and can also suppose JSON data types
Breakdown of a basic query
For right now we're just using basic SQL standard
Each table in our database will have fields, each record will have a row and column. We need to know what we want to look at to form our query properly
Each SQL query is going to start and include commands such as SELECT, UPDATE, INSERT and DELETE
You want to figure out what you want first, and then try and translate it into a query. For example if you want to look at all customers in your database you might say "SELECT * FROM Customers;"
Asking the database to give results in any order or organizational pattern we want without changing the data can give us the ability to play with the data in more ways
SQL has the options of Ascending or Descending
These are denoted by ASC and DESC functions, These are used by saying ORDER BY
Example 1: If we wanted to make sure we have unique library patrons, we could look for addresses to make sure we are only seeing unique addresses and no duplicates
Example 2: Looking at books we might want to make sure we are looking at a distinct or unique catalog of books, without duplication so we can take accurate inventory of what we might be missing
Other functions with SQL
SQL has a number of other functions that are helpful as well
CAUTION: The type of SQL you're using affects what functions there are and how they are labelled
Some functions are there in all the common dialects of SQL and look the same
Here are some examples of what functions look like by dialect
For example, if you wanted to find Natural logarithm of x
Standard SQL says it's LN(x)
MSSQL says it's LOG(x)
MySQL says it can be either one
How SQL queries are processed
FROM/JOIN --> WHERE --> GROUP BY --> HAVING --> SELECT --> ORDER BY --> LIMIT