I am trying to use this query in Postgres:
SELECT ean, count(nif)
FROM produto P, fornece_sec F
WHERE P.ean = F.ean
GROUP BY P.ean
HAVING count(nif) > 1;
I get this error:
ERROR: column reference "ean" is ambiguous LINE 1: SELECT ean, count(nif)
If I change the query to:
SELECT P.ean, count(nif)
FROM produto P, fornece_sec F
WHERE P.ean = F.ean
GROUP BY P.ean
HAVING count(nif) > 1;
Appears another error:
ERROR: missing FROM-clause entry for table "p" LINE 4: GROUP BY P.ean
Those two tables are created this way:
create table produto (
ean char(13) not null unique,
design varchar(255) not null,
categoria varchar(80) not null,
forn_primario char(9) not null,
data date not null,
constraint ean_size CHECK (Length(ean)=13),
constraint pk_produto primary key(ean),
constraint fk_produto_categoria foreign key(categoria) references categoria(nome) ON DELETE CASCADE,
constraint fk_produto_fornecedor foreign key(forn_primario) references fornecedor(nif));
create table fornece_sec (
nif char(9) not null,
ean char(13) not null,
constraint pk_fornece_sec primary key(nif, ean),
constraint fk_fornece_sec_fornecedor foreign key(nif) references fornecedor(nif),
constraint fk_fornece_sec_produto foreign key(ean) references produto(ean) ON DELETE CASCADE);
Note: the attribute nif in fornece_sec table is the same type of the attribute forn_primario in the product table.
GROUP BYseems to contain unicode, not ASCII. Maybe the P is non-ASCII character that looks like P. - tonypdmtrJOIN- Eric