Skip to content

London 9_Natalie Zablotska_SQL_week2 - #29

Closed
nataliiazab wants to merge 2 commits into
CodeYourFuture:mainfrom
nataliiazab:main
Closed

London 9_Natalie Zablotska_SQL_week2#29
nataliiazab wants to merge 2 commits into
CodeYourFuture:mainfrom
nataliiazab:main

Conversation

@nataliiazab

@nataliiazab nataliiazab commented May 20, 2023

Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

Briefly explain your PR.

Questions

Ask any questions you have for your reviewer.

@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@Alexander-Rennie Alexander-Rennie left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great effort! There is nothing really wrong here, but some minor comments have been annotated.

Comment thread E-Commerce/readme.md
```sql
select * from products where product_name ilike '%socks%';
```

@Alexander-Rennie Alexander-Rennie Jun 26, 2023

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CORRECT (although do note your query will also return products containing 'SOCKS', or anything mixed case)

Comment thread E-Commerce/readme.md
where pa.unit_price > 100
order by unit_price desc;
```

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CORRECT

Comment thread E-Commerce/readme.md
from products p INNER JOIN
product_availability pa on (p.id = pa.prod_id)
order by unit_price desc limit 5;
```

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CORRECT

Comment thread E-Commerce/readme.md
LEFT JOIN products p on (p.id = pa.prod_id)
where s.country = 'United Kingdom'
order by pa.unit_price desc;
```

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whilst this is essentially correct, be careful about the use of LEFT JOIN instead of INNER JOIN, depending upon the output you require. The question here suggests we are interested in products, whereas suppliers here who have no product_availability or product may still yield rows in this output. (See https://www.postgresqltutorial.com/postgresql-tutorial/postgresql-joins/ for clarification.)

Comment thread E-Commerce/readme.md
order_items oi on (o.id = oi.order_id)
INNER JOIN customers c on (o.customer_id = c.id)
where c.name = 'Hope Crosby';
```

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CORRECT

Comment thread E-Commerce/readme.md
INNER JOIN order_items oi on (oi.product_id = p.id and oi.supplier_id = pa.supp_id)
INNER JOIN orders o on (o.id = oi.order_id)
where o.order_reference = 'ORD006';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CORRECT

Comment thread E-Commerce/readme.md
INNER JOIN suppliers s on (s.id = oi.supplier_id)
INNER JOIN orders o on (oi.order_id = o.id)
inner join customers c on (c.id = o.customer_id);
```

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is essentially correct, although the earlier point about LEFT JOINs also applies here. If we are only interested in products from orders, we should be careful to avoid products which have not been ordered. Also, it is generally good practice to be consistent in the casing of SQL keywords, for purposes of readability and style rather than any impact on functionality. (Here, for example, 'select' is lower case, 'LEFT JOIN' is upper, and 'INNER JOIN' appears as both.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants