0
I have the following problem to solve:
I need to make an Sql that refers to an X table
"Tabela X":
id coluna1 coluna2
"Tabela 2":
id coluna1 coluna2 coluna3.
In "Table X" column 1 and column 2 are foreign keys of "Table 2" both with different values.
In Sql I need to return the id of the tableX the id of table 2 and any column of table two for the 2 foreign key fields.
Data sample:
Tabela X:
id coluna1 coluna2
1 1 2
2 2 1
3 3 1
4 4 2
column 1 and column 2 are primary key of table 2.
Tabela 2:
id coluna1 coluna2 coluna 3
1 TB2val1 TB2outro1 TB2aux1
2 TB2val2 TB2outro2 TB2aux2
3 TB2val3 TB2outro3 TB2aux3
4 TB2val4 TB2outro4 TB2aux4
I tried to do so:
select tx.id,tx.coluna1,tx.coluna2,t2.coluna1 from tabelaX tx,tabela2 t2
where tx.id=t2.id group by tx.id,tx.coluna1,tx.coluna2,t2
but I could not complete the sql because I need to join the other query in select and I could not find how to do it.
I would need a return on select with these columns:
idTabela1 idTabela2 idTabela2 tabela2.coluna1 tabela2.coluna1
The first result would have to be like this:
First row select result I need: 1 1 2 TB2val1 TB2val2
I searched here and probably this issue is solved with a Union select.
tabela2.coluna1 tabela2.coluna1
the same field 2x ?– Rovann Linhalis