1
I need to join between 2 tables where I need only the last record of the 2nd table (only 1 record of table 2 for each record of table 1).
SELECT a.Campo1, a.Campo2, a.Campo3, a.Campo4, b.Campo1, b.Campo2
FROM Tabela1 a
LEFT JOIN Tabela2 b ON b.Campo1 = a.Campo1 AND (b.Campo2 = (SELECT b.Campo2 FROM Tabela2 c WHERE c.Campo1 = a.Campo1) AND ROWNUM = 1)
trying this way returns the error:
ORA-01799: a column cannot be externally connected to a sub-consumption
Can someone help me?
What’s wrong with
SELECT a.Campo1, a.Campo2, a.Campo3, a.Campo4, b.Campo1, b.Campo2 FROM Tabela1 a LEFT JOIN Tabela2 b ON b.Campo1 = a.Campo1
? I do not understand what is the purpose of this subselect and from what I see, it seems completely innocuous and unnecessary.– Victor Stafusa
A
having
together with the grouping would not solve?– Jefferson Quesado
The select in question returns more than 1 record from the second table, I only need the last record recorded in this table.
– Davy Correa