CST363 - Week 18
- YZ

- May 11, 2020
- 1 min read
Joining Tables Without Primary and Foreign Key Relationship
An example of this would be to do a self-join of a table named celebrities that contains names and birthdays of different celebrities.
In English, we want to find out: Who is younger than Bill Gates?
This is how we can code it in SQL:
SELECT table2.name
FROM celebrities AS table1
JOIN celebrities AS table2
ON table2.birthday < table1.birthday
WHERE table1.name = 'Bill Gates';
celebrities

Summary
This week, we continued to progress in the textbook. We learned how to insert, update, and delete data in a table. Additionally, we covered aggregate functions and using the GROUP BY and HAVING clauses to group rows together. Lastly, we read about coding subqueries, which are SELECT statements coded within another SQL statement.



Comments