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

Limit issue: Order by items must be in the select list if distinct is specified #229

Open
colin-rogers-dbt opened this issue Sep 23, 2024 · 0 comments

Comments

@colin-rogers-dbt
Copy link

Looks like the current approach to adding a limit to queries doesn't work if the user adds distinct to their model, example

with

source as (

    select * from "raw_emails"
),

renamed as (

    select

        id as email_id,
        email,
        email_top_level_domain

    from source

)

select distinct * from renamed order by (select null)
            offset 0 rows fetch first 1 rows only

Error:
('42000', '[42000] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]ORDER BY items must appear in the select list if SELECT DISTINCT is specified. (145) (SQLExecDirectW)')

We might be able to get around this by wrapping in a subquery

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant