How to do select in the bank involving foreign key and primary key?

2

I have a problem, I have two tables that are related to the foreign key and the primary key like this:

CREATE TABLE IF NOT EXISTS cargo(
id INT AUTO_INCREMENT NOT NULL,
nome_cargo varchar(50) not null,          "supervisor,gerente, etc..."
salario_cargo DECIMAL NOT NULL,
tipo_cargo VARCHAR(11) NOT NULL,        "administrador ou funcionario comum"
PRIMARY KEY (id)
   );

 CREATE TABLE IF NOT EXISTS funcionario(
id INT AUTO_INCREMENT NOT NULL,
rg VARCHAR(10) NOT NULL,
cpf VARCHAR(11) NOT NULL,
email VARCHAR(255) NOT NULL,
senha VARCHAR(50) NOT NULL,
nome VARCHAR(50) NOT NULL,
id_cargo INTEGER NOT NULL,
PRIMARY KEY (id)
 );
    ALTER TABLE funcionario ADD foreign key (id_cargo) REFERENCES cargo (id);

Every post has an id and the official id of the official table serves to identify the official post, but I do not know how to do the select from the official email. I can see if he is an administrator or a regular official. some codes but none worked, somebody help me please

    
asked by anonymous 04.04.2016 / 21:07

1 answer

4

Run this query:

SELECT NOME, EMAIL, NOME_CARGO, TIPO_CARGO
FROM FUNCIONARIO 
INNER JOIN CARGO ON CARGO.ID = FUNCIONARIO.ID_CARGO
WHERE EMAIL = '[email protected]'
    
04.04.2016 / 21:10