Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Hopefully Stupid Question
Spence,
There are no stupid questions ... but there are plenty of stupid
answers. None of which appear here. The posts in response to your
question
are quite good and you should learn a little SQL from them. In the mean
time, pick up a good book on SQL (not the Oracle manual ... its not
meant
to teach SQL, its more a reference manual) and play around [ with
scott/tiger? ].
I'm glad to see posts like this where basic questions are asked without someone feeding their own egos in response.
Here's another suggestion: use alias names for the tables. That
will make the query a lot easier to type. Reading queries with alias
names
will become second nature.
ie
Select t1.data1, t2.data2, t3.data3, t1.TS from table1 t1, table2 t2, table3 t3 where t1.TS = t2.TS and t2.TS = t3.TS; If the timestamp was consistant across all three inserts, which itmay be, this will work. See other posts for an explanation of why it might not work. The timestamp could differ even if all three rows were inserted as part of the same transaction if SYSDATE was used in the VALUES clause. If it was, the dates will have to potential to differ as the clock ticks away during the inserts. If you find this to be the case
jc
"spence" <devnull635_at_netscape.com> wrote in message
news:Gx730C.2p6_at_research.att.com
> Hi,
>
> Forgive me if I'm having a brain fart, but I can't seem to translate what I
> want to good SQL - I'm using Oracle 8.1.7. Here's the situation...
>
> I have say 3 tables and each of them has a character based timestamp (don't
> ask) with an identical fieldname, TS. I want to select various fields from
> each of the 3 tables and order the results based on the timestamp field they
> all have in common, TS. Perhaps something similar to:
>
> select
> table1.data1,
> table2.data2,
> table3.data3,
> table1.TS,
> table2.TS,
> table3.TS
> from
> table1, table2, table3
> order by TS;
>
> I realize that the above won't work because the TS in the order-by clause is
> ambiguous. How can I tell it to combine all the TSs and sort the rows based
> on that?
>
> Help!?!
>
> S
-- Posted via Mailgate.ORG Server - http://www.Mailgate.ORGReceived on Tue Jun 04 2002 - 17:48:37 CDT