Resources for Learning SQL

I have spent the past couple weeks working on the SQL lesson for my database class. For the first (of four) practice sets on SQL commands, I felt like SQL was really kicking my butt. I didn’t have a good grasp of all the commands and how to put them together.

The lectures on SQL in my class were very … dry. They mostly consisted of the professor introducing a new command and then demonstrating how it worked, over and over, in different queries. There weren’t any breaks for us to try little problems. And there wasn’t any overview that helped us learn how to break down a problem. I imagined something like, “If you’re trying to find this kind of information, think about using this combination of commands,” or perhaps, “You need to find this information. Can you imagine how to build up to the right query? Start by formulating the query for X.” Instead, the lectures went more like this: “Let’s learn the JOIN command; here is how it works for this query. And here is how it works for this query. And here is how …”

After watching nine different lectures about SQL commands, I wasn’t always sure where to look for information about the specific problem I was trying to solve. So I turned to teh intarwebs. I found two really nice resources:

Continue reading “Resources for Learning SQL”

Advertisements

Using Relational Algebra to Select Based on Query Results

The title of this post is a bit misleading, but it just goes to show how important it is to ask the right question. The other day, I was working on a challenge homework problem that basically proposed this challenge:

Use relational algebra to find all schools that offer every class Spanish majors want to take.

(The actual problem was different, but I don’t want future students to find the answer just by searching for the homework question!) Assume we have two relations:

  • Relation S: A list of schools and the classes they offer.
  • Relation C: A list of students, their majors, and the classes they want to take.

At first, all I could imagine was that I needed to find every class Spanish majors wanted to take, and then use the results of that query to iterate over the list of schools. I couldn’t think of a different way to approach the problem … until I thought back to the approach I used in the maximum value problem I discussed yesterday. Continue reading “Using Relational Algebra to Select Based on Query Results”

Finding a Maximum Value with Relational Algebra

I finally coded the correct answer to my maximum value problem in relational algebra. There are plenty of answers out there (see stack overflowcodeblow, stack overflow again, …) but my brain didn’t want to accept that this solution worked. It helps me to visualize what’s happening.

Say we have this simple relation of letters and numbers:

Letter Number
A 1
B 2
C 3
D 4

Continue reading “Finding a Maximum Value with Relational Algebra”

Tackling JSON and Relational Algebra

My Intro to Databases course moved on from XML to JSON, which I have to admit was less motivating for me. JSON has an interesting format, but I don’t really know what I would use it for. In any case, we didn’t spend much time on it. I zipped through that section and onto a more hefty topic: relational algebra.

I had a somewhat satisfying moment when my husband, an electrical engineer, offered to help me with a homework problem I was stuck on. (He is my go-to guy for helping me learn or relearn the more complex math and logic problems I encounter in my computer science courses.) I started to explain the homework problem, when he stopped me: “Wait, what is relational algebra?” I explained the general idea and the allowed operations, and he admitted, “Huh, I have never done that before.” As he wandered back to his own work, I turned back to my desk with even more resolve. A technical concept I could master that he doesn’t already know? I’ll do it! Continue reading “Tackling JSON and Relational Algebra”