Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Databases and SQL: Refactor SQL queries #29113

Merged
merged 1 commit into from
Nov 25, 2024

Conversation

dekr1sh
Copy link
Contributor

@dekr1sh dekr1sh commented Nov 22, 2024

Because

This PR refactors SQL queries to adhere to best practices and ensure compatibility. It modifies the GROUP BY and HAVING clauses to explicitly reference the necessary columns and ensure proper SQL execution order respectively.

This PR

  • Updated GROUP BY clause to include users.name for adherence to best practices.
  • Modified HAVING clause to reference COUNT(posts.id) directly instead of the alias posts_written, aligning with the SQL execution order since column aliases are not available during the HAVING phase.

Issue

Closes #28798

Additional Information

No additional information.

Pull Request Requirements

  • I have thoroughly read and understand The Odin Project curriculum contributing guide
  • The title of this PR follows the location of change: brief description of change format, e.g. Intro to HTML and CSS lesson: Fix link text
  • The Because section summarizes the reason for this PR
  • The This PR section has a bullet point list describing the changes in this PR
  • If this PR addresses an open issue, it is linked in the Issue section
  • If any lesson files are included in this PR, they have been previewed with the Markdown preview tool to ensure it is formatted correctly
  • If any lesson files are included in this PR, they follow the Layout Style Guide

- Updated `GROUP BY` clause to include `users.name` for adherence to
  best practices.
- Modified `HAVING` clause to reference `COUNT(posts.id)` directly
  instead of the alias `posts_written` aligning with the SQL execution
  order, as column aliases are not available during the HAVING phase.
@github-actions github-actions bot added the Content: Databases Involves the Databases course label Nov 22, 2024
Copy link
Contributor

@JoshDevHub JoshDevHub left a comment

Choose a reason for hiding this comment

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

Thank you for contributing 🚀

@JoshDevHub JoshDevHub merged commit 51b84f8 into TheOdinProject:main Nov 25, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content: Databases Involves the Databases course
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Databases and SQL: Issues with code snippets
2 participants