CST 363 - Learning Journal Week 2

 SQL has the ability to join tables. The join will use keys either primary keys or foreign keys. This is an example of joining where something other than keys would be used. 

Example (Google search for examples to join tables where something other than keys are used):

Obtain the names of all pairs of products where the price of the first product is greater than the price of the second product. (Google AI - Gemini example)

SQL code: 

select P1.ProductName as HigherPricedProduct, P2.ProductName as LowerPricedProduct, P1.Price as                    HigherPrice, P2.Price as LowerPrice

from Product as P1

join Product as P2 on P1.Price > P2.Price

order by P1.Price desc, P2.Price desc;


SQL language is a complex language that is very beneficial when working with large datasets. Majority of the time it is easy(currently) in the course to translate an English sentence into SQL, but as the course goes on it will get more complex. Examples of translating English into SQL get complicated when they're complicated joins, or subqueries that need to be handles. Examples of harder SQL queries are 'when in a class you want a name of a student that has a higher score on an exam than the average'. Grouping SQL queries can also get complicate when it is vague like 'find the first class each student took in their college career'. Vague English statements get harder to translate into SQL, therefore is it important to be concise when using SQL. I like how SQL allows one to learn in depth about their dataset that they are working with. 


Comments

Popular posts from this blog

CST 349 - Week 4 Learning Journal

CST349 Week 2 - Learning Journal

CST 349 - Week 5 Learning Journal