Skip to content

SQL: WHERE clause doesn't utilise alias of SELECT expression/func successfully #29983

@elasticmachine

Description

@elasticmachine

Original comment by @gingerwizard:

Query as follows:

SELECT respondent_id, applicant_income_000s/loan_amount_000s AS income_to_earnings_ratio FROM mortgages WHERE income_to_earnings_ratio > 1 ORDER BY income_to_earnings_ratio

The WHERE clauses here uses an alias. The query complains the income_to_earnings_ratio cannot be found i.e.

Found 1 problem(s)
line 1:101: Unknown column [income_to_earnings_ratio]

This is inconsistent with our ability to use aliases in GROUP BY and ORDER BY. Repeating the expression in the WHERE works.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions