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

count query causes error [CORE3654] #4004

Closed
firebird-automations opened this issue Nov 7, 2011 · 4 comments
Closed

count query causes error [CORE3654] #4004

firebird-automations opened this issue Nov 7, 2011 · 4 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: Pieter Libin (pieter_emweb.be)

Consider we have a new database containing the following tables:

create table "table_b" (
"id" bigint primary key,
"name" varchar(50) not null
);

create table "table_a" (
"id" bigint primary key,
"date" date,
"b_id" bigint,
constraint "fk_table_a_b" foreign key ("b_id") references "table_b" ("id") on update cascade on delete cascade
);

When we try to execute a count query, which appears to me to be valid SQL:

select count(1) from ( select B."id", B."name", A."id", A."date", A."b_id" from "table_b" B join "table_a" A on A."b_id" = B."id");

an error is reported

column id was specified multiple times for derived table <unnamed>

@firebird-automations
Copy link
Collaborator Author

Commented by: @dyemanov

A derived table must have unique column names, even if you don't reference them outside that derived table. In your case, an alternative alias for either http://B.ID or http://A.ID is required. I'm not really sure this should be treated as a bug.

@firebird-automations
Copy link
Collaborator Author

Commented by: Sean Leyne (seanleyne)

As Dmitry pointed out the column names need to unique, so you would need to assign an 'alias' to the column, as in:

select count(1)
from (
select
B."id",
B."name",
A."id" as ID2,
A."date",
A."b_id"
from "table_b" B
join "table_a" A on A."b_id" = B."id"
);

@firebird-automations
Copy link
Collaborator Author

Modified by: Sean Leyne (seanleyne)

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Won't Fix [ 2 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

status: Resolved [ 5 ] => Closed [ 6 ]

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

1 participant