DEV Community

averagealloy
averagealloy

Posted on

The SQL was better!

What is SQL?

Before computers, there were written records. For example, in a western movie there would be a General store. This general store would keep track of how many items were sold in a week. Today we have computers. People before my time had used languages like C, C++, and java to build databases. Now, what's a database? A database is where your information is being held. Going back to the analogy prior, a database would be the book or piece of paper that the shopkeep would write down all the information about sales for the week. But what if he or anybody else in this fictional western town had a question about what they bought the week prior? In the land of make-believe, he would have to dust off those glasses and mosey over to his record reading each name just to find that you got a poker set and some twine. That sounds brutal because it was. Only if there was a language that spoke with a database that held all the information you were looking for and asking a question to that database easier? There is and it's SQL. SQL stands for Structured Query Language, I just think about it like a really complex magic eight balls. You use SQL so ask questions and get answers in return.

How does it work?

It starts with a question to your database. Were going to stick with the general store model here as well. let's say our database holds customers. Each customer has information about them such as what they got prior to there current visit so they could get what they want this visit.

Edgecase City!

It's important to think about edge cases early on because the sooner you work them in the less stress you will have later! So what edge cases do we need to consider. Number one would be lookup. How on earth are we going to find a customer? By name? I am not sure usually in that western movie there is a dual and in that dual one guy says to the other "this town isn't big enough for the two of us!". So that's out! A reasonable option would be an ID. Each user would have an ID so we could look up the third dirty dan because he would have a unique ID. This, however, is more about database set up rather than SQL sow we will get back to that.

Your garden variety query.

What would a query look like for this database? Let's say we want all customers who bought apple's the query would look something like this:

SELECT * FROM storeRecord WHERE purchased = "apples"

A little bit to unpack here which is good SQL reads like English so we are in luck! the SELECT and FROM make sense but what is the *? Well, the star means everything. No, I am not kidding, it makes more sense when we read it out. Select everything from a specific point in our database specifically where this condition is met.

A peek inside the looking glass

This is the Highest level explanation I can give without getting more technical. SQL allows for more advance queries from multiple tables and receiving different types of data. It's pretty cool! Hopefully, this gets you on the right path to mastering the art of asking your database questions!

-Thanks, Mike

Top comments (0)