Week 2 Learning Journal SQL
1. Example of a join that does not use keys
English sentence:
Find all pairs of students and instructors where the student’s total credits are greater than the instructor’s salary divided by 1,000.
SQL Query:
SELECT s.name AS student_name, i.name AS instructor_name, s.tot_cred, i.salary
FROM student s
JOIN instructor i
ON s.tot_cred > (i.salary / 1000);
In this case, the join is not based on primary/foreign keys but on a comparison condition (>). It shows a scenario where a logical relationship (credits compared to salary) is more important than a structural relationship between tables.
2. My opinion of SQL as a language
I think SQL is a very powerful and flexible language because it allows you to describe what data you want instead of how to compute it step by step. The declarative nature of SQL makes it easy to write complex queries with relatively little code. Once you understand the fundamentals (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY), you can accomplish a lot.
3. Ease of learning and use
At first, SQL feels simple because the syntax is very close to English. However, as soon as you add multiple joins, subqueries, or aggregation, it can become more challenging. I would say SQL is moderately easy to learn at a basic level but requires practice to master more advanced queries.
4. Challenges when translating from English to SQL
The hardest part for me is translating ambiguous or complex English questions into precise SQL logic. For example:
When the question involves multiple conditions across several tables.
When aggregation (like counting or averaging) needs to be combined with grouping and filtering.
When the English phrasing hides the need for a subquery (e.g., “find students who have more credits than the average credits of all students”).
Those situations require breaking down the English into logical steps, then carefully mapping each step to SQL.
Comments
Post a Comment