Skip to content

Columns not found when joining subquery #467

Closed

Description

@maxhawkins

If you define a new column in a subquery and do a join the new column can't be referenced by the containing query. A "does not exist" error is returned.

An example:

CREATE TABLE users (
    user_id INT PRIMARY KEY
);
CREATE TABLE names (
    user_id INT REFERENCES users,
    first_name TEXT,
    last_name TEXT
);

SELECT
    user_id,
    full_name
FROM users
JOIN (
    SELECT
        user_id,
        first_name || last_name AS full_name
    FROM names
) AS full_names USING (user_id);

Returns column "full_name" does not exist, though the query is valid.

Activity

  1. changed the title [-]Columns Not Found When Joining Subquery[/-] [+]Columns not found when joining subquery[/+] on May 6, 2020
  2. added 3 commits that reference this issue on May 14, 2020
    37b21db
    87096f7
    9ffbab1
  3. added a commit that references this issue on May 14, 2020
    19dda2b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions