Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> SQL Question
Hello,
I would like to join two tables sequentially (I don't know the right term for this; I try to explain below). I am a programmer, but inexperienced with sql; I'd appreciate it if someone could help me out.
I have a "schedule" table (which we can assume has already been sorted by the schedule id) with a site id number and a value like:
site_id type
101 A 101 B 101 B 102 C 102 B 102 B 103 A 103 A
and I want to join it with an "objects" table, which has a link to a site, like:
obj_id site_id
1 101 2 102 3 101 4 101 5 102 6 103 7 103
How would I join them such that the first object with site_id of 101 is joined with the type of the first schedule item with site_id of 101, the second object of site 101 with the second schedule item from site 101, etc. in sequential order.
The result I want looks like:
obj_id type site_id
1 A 101 2 C 102 3 B 101 4 B 101 5 B 102 6 A 103 7 A 103
Do I need to use PL/SQL to achieve this? I feel like I don't, but
neither can I figure out how to "iterate" through the schedule table
without producing repeats. I can think of all kinds of ugly
programmatic ways to do it, but I feel like I'm missing an "aha" moment
for a SQL solution.
Any help would be appreciated.
Peace
Bill Mill
bill.mill at gmail.com
Received on Tue Dec 21 2004 - 13:47:49 CST