MySQL Queries
And just when I thought I understood databases, SQL queries messed me up. Now I grasped SQL a lot easier than I did ERDs, probably because I spent so much time on ERDs. The trickiest part of SQL queries is joining tables. CodingDojo's website had .gifs showing each step of the query and how it is visualized. What I learned is that when creating queries for data that you want, it's like creating a trail through different tables.
How queries works:
select (the data that you want from the query)
from (select a table - usually the table that you have a specifying feature)
(insert any sort, order, join commands);
How join works:
from table1
join table2 on table1.id (or whatever is the primary key's name) = table2.id (the foreign key)
join table 3 on table2.id = table3.id etc.
One feature that I learned for join is that you can join another table without referencing the previous table that is joined (which is the most common type of joins).
from table1
join table2 on table1.id = table2.id
join table 3 on table3.id = table2.id
I also learned self-joins, which became very meta very quick. Self joins are basically tables referencing itself. Think of a table with users connected to a friendship table. You have a foreign ID from the users table in your friendship table to reference the users. But you also have a friend ID that is not referencing any other tables but itself (since you have the users, those are your friends). Confusing? It gets better;
How self-joins work:
select 'something'
from table1
join table 2 on table1.id = table2.(foreign key #1)
join table1 as table1' on table1'.id = table2.(foreign key #2)
This might not be the best illustration but if I find a better way to describe self-joins then I'll edit this entry!