Good morning I would like a help from how do I get two information in one table from another. I have a table of notes where I have the agent_id and ID_endereco, I want to get the agent name and the customer name in the table whose people field is personas.cgccpf.
To have the cgccpf of the agent I need to relate the agent_id of the note to the users table by the agent_id To have the client's cgccpf I have to relate the id_endereco to the address table by id_endereco. Bye all right inner join agents on agent.id_agent = notes.id_agent inner join address on endereco.id_endereco = notes.id_endereco
But how do I get the address.cgccpf and the agent.cgccpf in both and show the names of each one in the people table?
CREATE TABLE Notas (
id_nfcapa integer NOT NULL,
cgccpf decimal(14,0) NOT NULL,
tppessoa smallint NULL,
nronota integer NOT NULL,
serienf char(4) NOT NULL,
nro_endere decimal(17,0) NOT NULL, -- FK Endereço
id_agente integer NOT NULL -- FK Agente
);
CREATE TABLE Agentes (
id_agente integer NOT NULL, -- PK Agente
id_setor integer NOT NULL,
tppessoa smallint NOT NULL,
cgccpf decimal(14,0) NOT NULL, -- FK Pessoa
cargo smallint NOT NULL
);
CREATE TABLE Endereco (
nro_endere decimal(17,0) NULL, -- PK Endereço
cgccpf decimal(14,0) NOT NULL, -- FK Pessoa
tppessoa smallint NOT NULL,
seqendereco smallint NOT NULL,
tipoendereco char(1) NULL,
endereco char(30) NULL,
complemento char(10) NULL
);
CREATE TABLE Pessoas (
cgccpf decimal(14,0) NOT NULL, -- PK Pessoa
tppessoa smallint NOT NULL,
nomepessoa char(40) NULL,
nomeguerra char(20) NULL,
dtfundacao date NULL,
rg char(14) NULL,
);
Thank you
Ronie