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

Wrong result in left join #63929

Closed
fhh-coder opened this issue May 16, 2024 · 2 comments
Closed

Wrong result in left join #63929

fhh-coder opened this issue May 16, 2024 · 2 comments
Assignees

Comments

@fhh-coder
Copy link

When I execute the following SQL statement, I expect the result of field b to be null, but the result is 0.

select l.*, r.* from 
( select 'a' as a ) l
left join 
( select '1' as a, 1 as b ) r 
on l.a = r.a;

image

My version is 23.8.2.1

image

@fhh-coder fhh-coder added the potential bug To be reviewed by developers and confirmed/rejected. label May 16, 2024
@kitaisreal kitaisreal added question Question? and removed potential bug To be reviewed by developers and confirmed/rejected. labels May 16, 2024
@kitaisreal
Copy link
Collaborator

kitaisreal commented May 16, 2024

By default, ClickHouse does not make non joined columns for LEFT, RIGHT, FULL JOIN Nullable, so it uses default values for non joined rows.
This behaviour can be controlled with setting https://clickhouse.com/docs/en/operations/settings/settings#join_use_nulls.

select l.*, r.* from
( select 'a' as a ) l
left join
( select '1' as a, 1 as b ) r
on l.a = r.a SETTINGS join_use_nulls = 1;

   ┌─a─┬─r.a──┬────b─┐
1. │ a │ ᴺᵁᴸᴸ │ ᴺᵁᴸᴸ │
   └───┴──────┴──────┘

@fhh-coder
Copy link
Author

get it!

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

No branches or pull requests

3 participants