How to write this QUERY

From: javaq <nougain_at_hotmail.com>
Date: 24 Dec 2001 23:22:44 -0800
Message-ID: <e9af93aa.0112242322.6dee10cc_at_posting.google.com>


How to write following SQL query


I have four tables like following

CREATE TABLE T1 (ID NUMBER PRIMARY KEY, TITLE VARCHAR2(100));  -- JJ
CREATE TABLE T2 (ID NUMBER PRIMARY KEY, TITLE VARCHAR2(100));  -- KK
CREATE TABLE T3 (ID NUMBER PRIMARY KEY, TITLE VARCHAR2(100));  -- LL
CREATE TABLE A  (ID_STR VARCHAR2(10), PRIORITY NUMBER);

--Few examples of data in T1, T2, T3 are ...

INSERT INTO T1 VALUES (1, 'This is first  in T1');
INSERT INTO T1 VALUES (2, 'This is Second in T1');
INSERT INTO T1 VALUES (3, 'This is Third  in T1');
INSERT INTO T2 VALUES (1, 'This is first  in T2');
INSERT INTO T2 VALUES (2, 'This is Second in T2');
INSERT INTO T3 VALUES (1, 'This is first  in T3');
INSERT INTO T3 VALUES (2, 'This is Second in T3');

--Few examples of data in A are...

INSERT INTO A VALUES ('JJ001', 3);
INSERT INTO A VALUES ('JJ002', 1);
INSERT INTO A VALUES ('JJ003', 2);
INSERT INTO A VALUES ('KK001', 2);
INSERT INTO A VALUES (null,    3);
INSERT INTO A VALUES ('LL001', 3);
INSERT INTO A VALUES ('LL002', 1);

Now what I want is to write a query which returns following
(1) ID_STR and PRIORITY from A
(2) TITLE From concerned table based on the ID_STR (first two chars

    signify the table eg KK points to T2 followed by three digit     ID)

NOTE: 1. In A ID_STR can be null and the format of ID_STR is fixed ie

         table identifier (either JJ, KK, LL) followed by three digit
         place.
      2. If the ID_STR is null, the TITLE should be empty (or null)
      3. I need to execute the query finally in Java Program.

Many Thanks Received on Tue Dec 25 2001 - 08:22:44 CET

Original text of this message