How to make two Join Inner in one table?

Asked

Viewed 56 times

-3

CREATE TABLE FUNCAO
(
ID_FUNCAO INT IDENTITY(1,1),
NOME_FUNCAO VARCHAR(100),
SALARIO VARCHAR(100),
DATA VARCHAR(100),
CONSTRAINT PK_FUNCAO PRIMARY KEY (ID_FUNCAO)
)

CREATE TABLE DEPARTAMENTO
(
ID_DEPARTAMENTO INT IDENTITY(1,1),
NOME_DEP VARCHAR(100),
ID_FUNCAO INT,
CONSTRAINT PK_DEP PRIMARY KEY (ID_DEPARTAMENTO),
CONSTRAINT PK_DEP_FUNCAO FOREIGN KEY (ID_FUNCAO)
REFERENCES FUNCAO (ID_FUNCAO)
)

In the VS Program the combobox Function and Salary The data come through the function table(did Inner Join)

I intend that on gridview date appear the two tables? only one appears. How to make two Inner Join in a select?

I’m using that select

string sql4A = "SELECT DP.ID_DEPARTAMENTO, DP.NOME_DEP, FUNCAO.NOME_FUNCAO, FUNCAO.ID_FUNCAO FROM DEPARTAMENTO AS DP INNER JOIN FUNCAO ON DP.ID_FUNCAO = FUNCAO.ID_FUNCAO";
  • "on gridview date appear the two tables? only one appears" That’s not clear, put the code in more detail. You wonder how to do two joins but only have two tables, only one Join already connects the two, which exactly wants to make you need to do another Join?

1 answer

-1


With the tables you put in the question we ask only one Inner Join. To display the contents of the two tables you must place the fields you want to display right after the select command. Below is an example:

select fc.ID_FUNCAO, fc.NOME_FUNCAO, fc.SALARIO, fc.DATA, dp.ID_DEPARTAMENTO, dp.NOME_DEP  
from funcao fc 
inner join departamento dp 
on dp.id_funcao = fc.id_funcao 

However, if you want to do one more Inner Join, you should add the Inner Join to it right after the end of the above mentioned query. I’ll leave it as a formula

Select * 
from table1 tb1
inner join table2 tb2 
on tb2.id_tb1 = tb1.id
inner join table3 tb3
on tb3.id_tb2 = tb3.id
(...)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.