I’m trying to build a query to grab all rows from Table 1, then check if a corresponding row exists in Table 2, and if so, pull some data, JOIN and insert into Table 3. This will make more sense in pseudocode – so here’s what I’m trying to do, procedurally, I’m just not sure how to implement this in PL/SQL.
For all rows in T1:
For all rows in T2:
if (T1.mycolumn - T2.othercolumn) > 0:
INSERT INTO T3 (foo, bar) VALUES T1.foo, T2.bar
Thanks!
It sounds like you are describing something like
I’m not sure that’s actually what you want, though. Some sample data and the expected output would be helpful. In what you’re describing,
t1.foovalues may get inserted many times intot3because they match many different rows int2. Normally, there would be some sort of key that is common tot1andt2that you would use to determine whether an appropriatet2row exists and thet1.mycolumn > t2.otherColumncondition would just be another predicate