Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Alternate solution to Exercise 7 (Not an Issue) #6

Copy link
Copy link
@johnny-brav0

Description

@johnny-brav0
Issue body actions

First off, thanks for creating this repo. It really has helped me a lot in getting started with SQL.
Now as posted in the solutions for exercise 7, the solution, I feel, is quite static. So, I searched about the error, Error Code: 1093. You can't specify target table 'albums' for update in FROM clause I got while trying to solve it in a single query. The following solution works dynamically:

UPDATE albums
SET release_year = 1986
WHERE albums.id = (
    SELECT id
    FROM (SELECT a.id
        FROM albums AS a
        WHERE release_year IS NULL) AS c
);

Upon reading this article I found that the above used to be a complex query in earlier versions of MYSQL which involved creating a temporary table. But starting from version 5.6 onward it has been optimised. So, I assume it is safe to use.
Also, coming from python background, this feels quite satisfying to do the task in one line (query in this case).

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.