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

Fixes: Wrong SQL Query's are fixed now #28991

Closed
wants to merge 1 commit into from

Conversation

CodeMaverick2
Copy link

Description

Fixes - #28798

This PR addresses issues in the SQL queries presented in the Databases and SQL lesson. The following corrections have been made to ensure compliance with SQL standards:

  1. Updated First Query:

    • The GROUP BY clause now includes users.name alongside users.id to conform to SQL standards regarding the inclusion of non-aggregated columns in the GROUP BY statement.

    Before:

    SELECT users.id, users.name, COUNT(posts.id) AS posts_written
    FROM users
    JOIN posts ON users.id = posts.user_id
    GROUP BY users.id;

    After:

    SELECT users.id, users.name, COUNT(posts.id) AS posts_written
    FROM users
    JOIN posts ON users.id = posts.user_id
    GROUP BY users.id, users.name;
  2. Updated Second Query:

    • The HAVING clause now uses the aggregate function directly rather than the alias posts_written, which ensures that the query executes correctly.
    • The GROUP BY clause is also updated to include users.name.

    Before:

    SELECT users.id, users.name, COUNT(posts.id) AS posts_written
    FROM users
    JOIN posts ON users.id = posts.user_id
    GROUP BY users.id
    HAVING posts_written >= 10;

    After:

    SELECT users.id, users.name, COUNT(posts.id) AS posts_written
    FROM users
    JOIN posts ON users.id = posts.user_id
    GROUP BY users.id, users.name
    HAVING COUNT(posts.id) >= 10;

Impact

  • Improved Learning Experience: Correcting these SQL queries aligns them with standard SQL practices, enhancing the educational value of the lesson.

@github-actions github-actions bot added the Content: Databases Involves the Databases course label Oct 22, 2024
@JoshDevHub
Copy link
Contributor

Closed for stepping over the issue author

@JoshDevHub JoshDevHub closed this Oct 22, 2024
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.

2 participants