Querying three tables.

hi,
I am new to sql.
I am trying to write a query to retrive information from 3 tables but it is not working.
I need your help.
Problem:
when i try to retrive data from two tables using equlaity condition it is working fine.
SELECT table1.column1, table2.column2 FROM table1, table2 WHERE table1.column1 = table2.column1;
this is working fine and retriving 1200 rows
when i try to use the same condition for checking three tables its not giving correct output.
SELECT table1.column1, table2.column2 FROM table1, table2, table3 WHERE table1.column1 = table2.column1 AND table1.column1 = table3.column1;
this is also working fine and retriving 2400 rows instead of 1200 rows..
My requirement is to get o/p from somr columns of thre tables but the thing is column1 of three tables should match.
your help is greatly appreciated.

I am using three tables
username col. in dba_users should be equal to username col. in test and
grantee col. in dba_role_privs should be equal to username col. in both test and dba_users
dba_users and dba_role_privs and test tables.
desc dba_users
Name Null? Type
USERNAME NOT NULL VARCHAR2(30)
USER_ID NOT NULL NUMBER
PASSWORD VARCHAR2(30)
ACCOUNT_STATUS NOT NULL VARCHAR2(32)
LOCK_DATE DATE
EXPIRY_DATE DATE
DEFAULT_TABLESPACE NOT NULL VARCHAR2(30)
TEMPORARY_TABLESPACE NOT NULL VARCHAR2(30)
CREATED NOT NULL DATE
PROFILE NOT NULL VARCHAR2(30)
INITIAL_RSRC_CONSUMER_GROUP VARCHAR2(30)
EXTERNAL_NAME VARCHAR2(4000)
desc dba_role_privs
Name Null? Type
GRANTEE VARCHAR2(30)
GRANTED_ROLE NOT NULL VARCHAR2(30)
ADMIN_OPTION VARCHAR2(3)
DEFAULT_ROLE VARCHAR2(3)
desc test
Name Null? Type
USERNAME NOT NULL VARCHAR2(30)
TYPE_ID VARCHAR2(2)
PASSWORD VARCHAR2(30)

Similar Messages

  • Single query for querying three tables

    Hi All,
    We are trying to construct a sql query(a single query), which can perform the below functionality.
    Assume, that there are three tables,
    TABLE1: 3 Columns
    1) ID -> PRIMARY KEY
    2) TYPE -> Allows only values 'A' or 'B'
    3) REF_ID(this can refer to TABLE2(ID) or TABLE3(ID)).
    TABLE2: 2 Columns
    1) ID -> PRIMARY KEY
    2) DETAILS -> Any normal text
    TABLE3: 2 Columns
    1) ID -> PRIMARY KEY
    2) DETAILS -> Any normal text
    We need to come up with a query that, given TABLE1's(ID), we need to fetch the corresponding record in TABLE1, and we need to fetch the corresponding record from TABLE2 or TABLE3, depending on the below conditions.
    If the TYPE for the TABLE1's(ID) is 'A'
    Then get the details from TABLE2's by mapping TABLE1.REF_ID = TABLE2.ID
    If the TYPE for the TABLE1's(ID) is 'B'
    Then get the details from TABLE3's by mapping TABLE1.REF_ID = TABLE3.ID
    We need to accomplish all these tasks in a single query.
    Thanks for your kindly help,
    Sreenivasan

    SQL> select * from test_qry1;
    ID T REF_ID
    1 A 100
    2 A 200
    3 B 300
    SQL> select * from test_qry2;
    ID DETAILS
    100 Human Resources
    200 It Services
    300 Relationships
    SQL> select * from test_qry3;
    ID DETAILS
    100 Human Beings
    200 Conference
    300 Used things
    SQL> SELECT t1.ID,
    DECODE(t1.type,'A',( SELECT t2.details FROM test_qry2 t2 WHERE t1.ref_id = t2.id
    'B',( SELECT t3.details FROM test_qry3 t3 WHERE t1.ref_id = t3.id
    ) details
    FROM test_qry1 t1;
    ID DETAILS
    1 Human Resource
    2 It Services
    3 Used things
    Try with this query.
    Thanks,
    Vissu......

  • Left join query with join of three tables

    I'm trying to build a query which has me stumped. Most of the query is fairly straightforward but I've run into an issue I'm not sure how to solve.
    Background:
    We have actions stored in i_action.
    We have the available attributes for each type of action. The available attributes for each action are described in shared_action_attribute. Each type of action may have up to three attributes or none at all.
    We have the values stored for the attributes in i_attribute_value.
    A written example:
    We have a transfer action (action_code B4). The entry of the B4 action into i_action records the fact that the transfer occurred and the date on which it occurred. The available attributes for a transfer action are the receiving function code, the receiving unit number, and the transfer reason code. These available attribute types and their order are stored in shared_action_attribute. The actual values of the attributes for a specific transfer action are stored in i_attribute_value.
    Now i_action and i_attribute_value can be directly linked through action_seq in i_action and ia_action_seq in i_attribute_value. A left join built between these two tables provides results for all actions (including actions which have no attributes) and attribute values (see query 1 below).
    There are two issues. First, I only want the first two attributes. In order to specify the first two attributes, I also have to link i_attribute_value to shared_action_attribute (which is where the order is stored). I can build a simple query (without the left join) linking the three tables but then actions with no attributes would be excluded from my result set (see query 2 below).
    The second issue is that I would actually like one row returned for each action with first_attribute and second_attribute as columns instead of two rows.
    The final query will be used to create a materialized view.
    Here are the tables and examples of what's stored in them:
    TABLE i_action
    Name Type
    ACTION_SEQ NUMBER(10)
    ACTION_DATE DATE
    ACTION_CODE VARCHAR2(3)
    DELETED VARCHAR2(1)
    EXAMPLE ROWS
    ACTION_SEQ ACTION_DATE ACTION_CODE DELETED
    45765668 09-OCT-09 B2 A
    45765670 09-OCT-09 BA A
    45765672 09-OCT-09 B6 A
    45765673 09-OCT-09 B4 A
    45765674 09-OCT-09 G1 A
    45765675 09-OCT-09 M3 A
    TABLE i_attribute_value
    Name Type
    IA_ACTION_SEQ NUMBER(10)
    SACTATT_SACT_CODE VARCHAR2(3)
    SACTATT_SAT_TYPE VARCHAR2(3)
    VALUE VARCHAR2(50)
    EXAMPLE ROWS
    IA_ACTION_SEQ SACTATT_SACT_CODE SACTATT_SAT_TYPE VALUE
    45765668 B2 ACO 37B
    45765670 BA ROA D
    45765670 BA ROR P
    45765672 B6 CAT C
    45765673 B4 RFC E
    45765673 B4 TRC P
    45765673 B4 RUN 7
    45765674 G1 SS 23567
    45765674 G1 ASG W
    TABLE shared_action_attribute
    Name Type
    SACT_CODE VARCHAR2(3)
    SAT_TYPE VARCHAR2(3)
    ORDER NUMBER(2)
    TITLE VARCHAR2(60)
    EXAMPLE ROWS
    SACT_CODE SAT_TYPE ORDER TITLE
    B2 ACO 1 Office code
    BA ROR 1 Reason for reopen
    BA ROA 2 Reopen authority
    B6 CAT 1 Category
    B4 RFC 1 Receiving function code
    B4 RUN 2 Receiving unit code
    B4 TRC 3 Transfer reason code
    G1 SS 1 Staff sequence
    G1 ASG 2 Assignment reason
    QUERY 1:
    This is my current query along with its results. Most of it is straightforward select but one column is populated using the last_value analytical function (thanks to you guys). The last column in the below view stores the attribute value. What I want is to replace that single column with two columns named first_attribute and second_attribute and to eliminate any other attributes.
    SELECT ia.action_seq, ia.action_date, ia.action_code cod,
    NVL
    (LAST_VALUE (CASE
    WHEN ia.action_code = 'G1'
    AND iav.sactatt_sat_type = 'SS'
    THEN VALUE
    WHEN ia.action_code IN ('A0', 'A1')
    THEN '67089'
    END IGNORE NULLS
    ) OVER (PARTITION BY ia.ici_charge_inquiry_seq ORDER BY ia.action_date,
    ia.serial_number, ia.action_seq),
    '67089'
    ) staff_seq,
    value
    FROM i_action ia LEFT JOIN i_attribute_value iav
    ON iav.ia_action_seq = ia.action_seq
    WHERE ia.deleted = 'A';
    ACTION_SEQ ACTION_DA COD STAFF_SEQ VALUE
    45765668 09-OCT-09 B2 67089 37B
    45765670 09-OCT-09 BA 67089 D
    45765670 09-OCT-09 BA 67089 P
    45765672 09-OCT-09 B6 67089 C
    45765673 09-OCT-09 B4 67089 E
    45765673 09-OCT-09 B4 67089 P
    45765673 09-OCT-09 B4 67089 7
    45765674 09-OCT-09 G1 23567 23567
    45765674 09-OCT-09 G1 23567 W
    45765675 09-OCT-09 M3 23567
    QUERY 2:
    This query limits to the first two attributes but it also drops actions which have no attributes and it still creates multiple rows for each action instead of a single row with two columns for the attributes.
    SELECT ia.action_seq, ia.action_date, ia.action_code cod,
    NVL
    (LAST_VALUE (CASE
    WHEN ia.action_code = 'G1'
    AND iav.sactatt_sat_type = 'SS'
    THEN VALUE
    WHEN ia.action_code IN ('A0', 'A1')
    THEN '67089'
    END IGNORE NULLS
    ) OVER (PARTITION BY ia.ici_charge_inquiry_seq ORDER BY ia.action_date,
    ia.serial_number, ia.action_seq),
    '67089'
    ) staff_seq,
    value
    FROM shared_action_attribute saa, ims_action ia, ims_attribute_value iav
    WHERE iav.ia_action_seq = ia.action_seq
    AND iav.sactatt_sact_code = saa.sact_code
    AND iav.sactatt_sat_type = saa.sat_type
    AND saa.display_order IN ('1','2')
    AND ia.deleted = 'A';
    ACTION_SEQ ACTION_DA COD VALUE
    45765668 09-OCT-09 B2 67089 37B
    45765670 09-OCT-09 BA 67089 D
    45765670 09-OCT-09 BA 67089 P
    45765672 09-OCT-09 B6 67089 C
    45765673 09-OCT-09 B4 67089 E
    45765673 09-OCT-09 B4 67089 7
    45765674 09-OCT-09 G1 23567 23567
    45765674 09-OCT-09 G1 23567 W
    I found this pretty complex to try to write out - I hope I've been clear.
    Thanks so much!

    Ok, here's more information with a simplified question. I figured out the syntax for building my query with the three tables. My final query returns multiple rows (multiple attributes per action). Instead of multiple rows, I'd like two columns (first_attribute, and second_attribute) in a single row (I only need the first two attributes).
    Here's the action table:
    CREATE TABLE I_ACTION
      ACTION_SEQ               NUMBER(10)           NOT NULL,
      ACTION_DATE              DATE,
      ACTION_CODE              VARCHAR2(3 BYTE)     NOT NULL,
      DELETED                  VARCHAR2(1 BYTE),
    );With the following rows added:
    Insert into I_ACTION (ACTION_SEQ, ACTION_DATE, ACTION_CODE, DELETED)
                  Values (45765668, '09-oct-2009', 'B2', 'A');
    Insert into I_ACTION (ACTION_SEQ, ACTION_DATE, ACTION_CODE, DELETED)
                  Values (45765670, '09-oct-2009', 'BA', 'A');
    Insert into I_ACTION (ACTION_SEQ, ACTION_DATE, ACTION_CODE, DELETED)
                  Values (45765672, '09-oct-2009', 'B6', 'A');
    Insert into I_ACTION (ACTION_SEQ, ACTION_DATE, ACTION_CODE, DELETED)
                  Values (45765673, '09-oct-2009', 'B4', 'A');
    Insert into I_ACTION (ACTION_SEQ, ACTION_DATE, ACTION_CODE, DELETED)
                  Values (45765674, '09-oct-2009', 'G1', 'A');
    Insert into I_ACTION (ACTION_SEQ, ACTION_DATE, ACTION_CODE, DELETED)
                  Values (45765675, '09-oct-2009', 'M3', 'A');
    COMMIT;The attribute table is:
    CREATE TABLE I_ATTRIBUTE_VALUE
      IA_ACTION_SEQ          NUMBER(10)             NOT NULL,
      SACTATT_SACT_CODE      VARCHAR2(3 BYTE)       NOT NULL,
      SACTATT_SAT_TYPE       VARCHAR2(3 BYTE)       NOT NULL,
      VALUE                  VARCHAR2(50 BYTE),
    );With the following rows:
    Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
                           Values (45765668, 'B2', 'ACO', '37B');
    Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
                           Values (45765670, 'BA', 'ROR', 'P');
    Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
                           Values (45765670, 'BA', 'ROA', 'D');
    Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
                           Values (45765672, 'B6', 'CAT', 'C');
    Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
                           Values (45765673, 'B4', 'RFC', 'E');
    Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
                           Values (45765673, 'B4', 'RUN', '7');
    Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
                           Values (45765673, 'B4', 'TRC', 'P');
    Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
                           Values (45765674, 'G1', 'SS', '23567');
    Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
                           Values (45765674, 'G1', 'ASG', 'W');
    COMMIT;And finally, the shared table:
    CREATE TABLE SHARED_ACTION_ATTRIBUTE
      SACT_CODE      VARCHAR2(3 BYTE)               NOT NULL,
      SAT_TYPE       VARCHAR2(3 BYTE)               NOT NULL,
      TITLE          VARCHAR2(25 BYTE)              NOT NULL,
      DISPLAY_ORDER  NUMBER(2)                      NOT NULL
    );With the following rows:
    Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
                                 Values ('B4', 'RFC', 'Y', 'Rcv. Function Code', 1);
    Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
                                 Values ('B6', 'CAT', 'Y', 'Category', 1);
    Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
                                 Values ('G1', 'SS', 'Y', 'Staff Name', 1);
    Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
                                 Values ('B2', 'ACO', 'Y', '"Other" Office Code', 1);
    Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
                                 Values ('B4', 'RUN', 'Y', 'Receiving Unit Number', 2);
    Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
                                 Values ('B6', 'LEP', 'N', 'LEP Issue/Sub Category', 2);
    Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
                                 Values ('B4', 'TRC', 'Y', 'Transfer Reason Code', 3);
    Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
                                 Values ('B6', 'NEP', 'N', 'NEP Issue', 3);
    Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
                                 Values ('G1', 'ASG', 'Y', 'Assignment Reason', 2);
    Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
                                 Values ('B2', 'MSN', 'S', 'Machine Serial Number', 3);
    Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
                                 Values ('BA', 'ROR', 'Y', 'Reopen Reason', 1);
    Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
                                 Values ('BA', 'ROA', 'Y', 'Reopen Authority', 2);
    COMMIT;Now, this is my current query (it's changed from my first post):
    SELECT ia.action_seq, ia.ici_charge_inquiry_seq, ia.action_date,
           ia.serial_number, ia.reporting_office, ia.reporting_function,
           ia.reporting_unit, ia.action_code, ia.machine_serial_number,
           NVL
              (LAST_VALUE (CASE
                              WHEN ia.action_code = 'G1'
                                 THEN VALUE
                              WHEN ia.action_code IN ('A0', 'A1')
                                 THEN '67089'
                           END IGNORE NULLS
                          ) OVER (PARTITION BY ia.ici_charge_inquiry_seq ORDER BY ia.action_date,
                ia.serial_number, ia.action_seq),
               '67089'
              ) staff_seq,
           (CASE
              WHEN display_order = '1'
              THEN VALUE
           END) first_attribute,
           (CASE
              WHEN display_order = '2'
              THEN VALUE
           END) second_attribute
      FROM ims_action ia
      LEFT JOIN ims_attribute_value iav
           ON iav.ia_action_seq = ia.action_seq
      LEFT JOIN shared_action_attribute
           ON sactatt_sact_code = sact_code
         AND sactatt_sat_type = sat_type
    WHERE ia.deleted = 'A';Which gives me the following results:
    ACTION_SEQ ACTION_DA ACT STAFF_SEQ FIRST_ATTRIBUTE SECOND_ATTRIBUTE   
      45765668 09-OCT-09 B2  67089     37B                                
      45765670 09-OCT-09 BA  67089                     D                  
      45765670 09-OCT-09 BA  67089     P                                  
      45765672 09-OCT-09 B6  67089     C                                  
      45765673 09-OCT-09 B4  67089     E                                  
      45765673 09-OCT-09 B4  67089                     7                  
      45765673 09-OCT-09 B4  67089                                        
      45765674 09-OCT-09 G1  23567                     W                  
      45765674 09-OCT-09 G1  23567     23567                              
      45765675 09-OCT-09 M3  23567                                       The result I WANT is similar but I want the two separate attribute columns on one row as such:
    ACTION_SEQ ACTION_DA ACT STAFF_SEQ FIRST_ATTRIBUTE SECOND_ATTRIBUTE   
      45765668 09-OCT-09 B2  67089     37B                                
      45765670 09-OCT-09 BA  67089     P               D                  
      45765672 09-OCT-09 B6  67089     C                                  
      45765673 09-OCT-09 B4  67089     E               7                  
      45765674 09-OCT-09 G1  23567     23567           W                  
      45765675 09-OCT-09 M3  23567                          Thanks so much!

  • Join query for three tables

    Hi i have got this query that is a join of two tables but i need join for three tables i need the extended query
    select aauthlname aauthlnam aauthfname aauthfnam aisbn btitle
      from ( bsauthors as a inner join bsbook as b on aisbn = bisbn )
      into corresponding fields of table books
      where aauthlname like authorlname or aauthfname like authorfname
      order by aauthlname aauthfname a~isbn.

    Hi pavan
    Plz try the following querry for joins on three tables :
    " Customize it to ur requirements and tablenames
    Parameters : b type mara-matnr.
    select xmatnr xmtart xmatkl ywerks ylgort zmaktx
    into corresponding fields of table itab
         from (  ( mara as x inner join mard as y on xmatnr = ymatnr )
    inner join makt as z on xmatnr = zmatnr ) where x~matnr = a and
    y~werks
    = b .
    Plz see that there is atleast one field common between the three tables u want to use.
    Regards
    Pankaj

  • Report using three tables on group basis

    Hi,
    I wish to know a clue for the follwing report among three tables either using join or sub-query or PL/SQL Script as per the below desired output.
    Top 10 games by uniques / by volume
    It should produce something like this:
    Game     Uniques     Volumes     Game Start     Game End     Mins on Air     
    Top 5 movies beginning with "D"     2734     7924     9/24/06 9:59 PM     9/24/06 10:41 PM     42     
    Top 5 One Hit Wonders     2355     6471     9/24/06 9:07 PM     9/24/06 9:48 PM     41     
    Things you find in The Kitchen     1336     3600     9/24/06 10:41 PM     9/24/06 10:59 PM     18     
    Twisted Title Men in Black     770     1435     9/24/06 9:53 PM     9/24/06 9:59 PM     6     
    Anagram Lance Armstrong     884     1350     9/24/06 9:48 PM     9/24/06 9:53 PM     5     
    A.Bucks Jack and Jill...     593     824     9/24/06 8:59 PM     9/24/06 9:04 PM     4     
    Missing link ANY101     649     815     9/24/06 9:04 PM     9/24/06 9:07 PM     3     
    Parameters should be startDate and endDate.
    This query can be obtained from using the following tables: Calls, Games, Events, Event_Types
    Calls have a timestamp.
    Every game has event, such as start game or end game (see Event_Types), with its timestamp
    Volumes: Number of calls received for each game between start game date and end date
    Uniques: Unique Number of calls received for each game between start game date and end date
    (distinct cli)
    Mins on air: differences between start call and end call
    Relationship:
    The ID column from games table and game_id from events table is common.
    Assume if the event type id is 2 then it starts game and if 3 then game ends. Other type is irrelevant for this query.
    The id from event_type is mentioned in another table event_types as master with description. But it is not required to establish relationship with this table. As this code ( 2 or 3) is alredy availbel with event_type_id in the events table.
    Please assume the CLI number as dummy data.
    I have provided the structure and query to generate tables and populate testing data to sort out this issue at the earliest.
    I tried to perform this query but I wish to compare the result with the script given by experts as I’m not a core developer.
    1) desc calls
    Name Null? Type
    CLI NOT NULL VARCHAR2(255)
    CALL_DATE NOT NULL TIMESTAMP(6)
    insert into values('&CLI','&call_date')
    select substr(CLI,1,10),substr(call_date,1,22) from calls
    SUBSTR(CLI SUBSTR(CALL_DATE,1,22)
    0662740929 22-SEP-06 05.22.44.123
    0662740973 22-SEP-06 05.22.47.123
    0662740956 22-SEP-06 05.22.46.123
    0662740980 22-SEP-06 05.22.47.123
    0662740936 09-MAY-06 05.22.44.123
    0762740954 22-SEP-06 05.22.45.123
    0762740936 09-MAY-06 05.22.47.123
    0762740921 22-SEP-06 05.22.44.123
    0113456789 22-SEP-06 05.47.04.082
    0987654321 22-SEP-06 06.16.29.727
    0 22-SEP-06 06.17.28.141
    SUBSTR(CLI SUBSTR(CALL_DATE,1,22)
    0123456789 09-MAY-06 06.27.51.224
    0112740929 22-SEP-06 06.28.43.398
    0123456789 09-MAY-06 06.30.10.830
    0044791475 24-SEP-06 04.38.08.564
    0044791475 24-SEP-06 04.40.05.777
    0123456789 24-SEP-06 05.32.22.267
    0147258369 24-SEP-06 05.34.25.652
    0852147963 24-SEP-06 05.52.56.992
    0123456789 25-SEP-06 01.34.17.157
    0683379112 25-SEP-06 01.35.19.461
    0 25-SEP-06 03.09.12.347
    SUBSTR(CLI SUBSTR(CALL_DATE,1,22)
    0141411683 25-SEP-06 03.21.07.402
    0141411683 25-SEP-06 03.21.38.519
    0618769562 02-JUN-06 03.22.12.807
    0123456789 02-JUN-06 03.24.11.387
    0 25-SEP-06 03.25.13.152
    0141412179 25-SEP-06 03.25.38.424
    0123456789 02-JUN-06 03.26.57.687
    0607069617 02-JUN-06 03.27.02.720
    0014141168 26-SEP-06 03.30.55.290
    0618769562 25-SEP-06 03.31.21.141
    0141411683 25-SEP-06 03.31.45.952
    SUBSTR(CLI SUBSTR(CALL_DATE,1,22)
    0607069617 25-SEP-06 03.32.14.542
    0618769562 25-SEP-06 03.32.30.433
    0 25-SEP-06 03.32.43.292
    0141412179 25-SEP-06 03.33.07.166
    0 25-SEP-06 03.33.56.086
    0 25-SEP-06 03.34.03.918
    0123456789 26-SEP-06 03.34.21.193
    0 25-SEP-06 03.34.25.484
    0 25-SEP-06 03.34.39.126
    0 25-SEP-06 03.34.40.354
    0 25-SEP-06 03.34.51.231
    2)
    SQL> desc events
    Name Null? Type
    EVENT_TYPE_ID NOT NULL NUMBER(19)
    EVENT_DATE NOT NULL TIMESTAMP(6)
    GAME_ID NUMBER(19)
    insert into events values ('&EVENT_TYPE_ID','&EVENT_DATE',&GAME_ID')
    SQL> select substr(event_type_id,1,10),substr(event_date,1,20),substr(game_id,1,10) from events where game_id in (1918,1919,1920,1939,1958,1979,1999,2018,2040,2041,2061)
    SUBSTR(EVE SUBSTR(EVENT_DATE,1, SUBSTR(GAM
    3 26-APR-06 06.11.50.8 1939
    4 26-APR-06 06.12.05.6 1939
    5 26-APR-06 06.16.13.5 1939
    3 09-MAY-06 06.18.59.7 1920
    4 09-MAY-06 06.22.43.7 1920
    3 12-MAY-06 04.24.46.2 1920
    4 12-MAY-06 04.46.22.5 1920
    3 12-MAY-06 04.29.07.4 1920
    4 12-MAY-06 04.39.31.1 1920
    3 12-MAY-06 04.29.35.3 1920
    4 12-MAY-06 04.30.02.8 1920
    SUBSTR(EVE SUBSTR(EVENT_DATE,1, SUBSTR(GAM
    3 26-SEP-06 12.19.27.6 1958
    4 26-SEP-06 12.29.37.9 1958
    5 01-JUN-06 12.26.37.2 1958
    3 02-JUN-06 11.53.49.0 1979
    6 02-JUN-06 11.54.00.5 1979
    4 02-JUN-06 11.54.55.5 1979
    3 02-JUN-06 11.55.03.7 1979
    4 02-JUN-06 11.57.40.7 1979
    3 02-JUN-06 11.57.43.5 1979
    4 02-JUN-06 11.59.47.2 1979
    3 14-SEP-06 02.24.13.8 1999
    SUBSTR(EVE SUBSTR(EVENT_DATE,1, SUBSTR(GAM
    4 14-SEP-06 02.55.18.7 1999
    3 14-SEP-06 06.44.40.1 1999
    4 14-SEP-06 06.52.57.9 1999
    3 22-SEP-06 04.05.09.5 2018
    4 22-SEP-06 05.24.14.7 2018
    5 22-SEP-06 05.24.25.0 2018
    4 24-SEP-06 03.17.54.8 2018
    3 24-SEP-06 03.19.00.1 2018
    3) INSERT INTO games VALUES ('&ID'.'&NAME')
    SQL> desc games
    Name Null? Type
    ID NOT NULL NUMBER(19)
    NAME NOT NULL VARCHAR2(255)
    select substr(id,1,10),substr(name,1,25) from games;
    SUBSTR(ID, SUBSTR(NAME,1,25)
    1918 Copy of QN27030628
    1919 Copy of Copy of QN0104061
    1920 Copy of Copy of Copy of Q
    1939 Alex Game 8
    1958 QN27030628 Lee
    1979 Copy of QN01040611 9
    1999 Ale's Game
    2018 TF1 Game test 1
    2040 Test Game TF1sarah
    2041 BTAgilemedia Game Test
    2061 Copy of Copy of QN0104060
    Your help would be highly appreciated.
    Thanks
    Jayesh

    Hi,
    I am sending herewith SQL statement for populating data into the concern tables
    To make easier for further testing your script.
    insert into calls values (0772740929, 22-SEP-06 05.22.44.123)
    insert into calls values (0882740929, 22-SEP-06 05.22.44.123)
    insert into calls values (0772740929, 25-SEP-06 05.22.44.123)
    insert into calls values (0662740929, 27-SEP-06 05.22.44.123)
    insert into calls values (0452740929, 22-SEP-06 05.22.44.123)
    insert into calls values (0992740929, 24-SEP-06 05.22.44.123)
    insert into calls values (0992740929, 26-SEP-06 05.22.44.123)
    insert into events values (3, 22-SEP-06 05.22.44.123,1918)
    insert into events values (4, 22-SEP-06 05.32.44.123,1918)
    insert into events values (3, 24-SEP-06 05.22.44,1920)
    insert into events values (4, 24-SEP-06 05.42.44,1920)
    insert into events values (3, 26-SEP-06 05.22.44,1958)
    insert into events values (4, 26-SEP-06 05.52.44,1958)
    Insert into games values (1918,’ Copy of QN27030628’)
    Insert into games values (1920,’ Test Game TF1sarah’)
    Insert into games values (1958,’ Test Car Race’)
    Thanks
    jayesh

  • How can i Delete the data from three tables at a time  using same key.

    I am New to Oracle ADF, I have a Requirement Like these, I have three tables like Employee,Salaries,Teams all of these are having one common EmpNo as common attribute, I have Search form these will return the all the employees related to that search query, when i click on Delete button the particular employe Data should delete from all the three tables based on the EmpNo.
    Any Help is appreciable..

    1) The easiest way is to mark the foreign key constraints from SALARIES to EMPLOYEES and from TEAMS to EMPLOYEES as ON DELETE CASCADE. The DB server will then delete the necessary rows whenever you delete an employee row.
    2) Another way is to implement a Before-Delete-Row DB trigger on the EMPLOYEES table where you can delete the related rows in the other tables (have in mind, that if you have foreign keys you may get a Mutating Table Exception, so this approach might be not very good).
    3) An ADF way is to implement a custom EntityImpl class for the Employee entity and to override the remove() method where you can lookup the related TeamMember and Salary entities (through EntityAssoc accessors) and invoke their remove() methods too.
    4) Another ADF way is to implement a custom EntityImpl class for the Employee entity and to override the doDML() method where you can delete the necessary rows in SALARIES and TEAMS tables through JDBC calls whenever a DELETE operation is being performed on the underlying Employee entity.
    Dimitar

  • Joining three tables

    I have to join three tables but i m getting error as given below:
    Error i m getting-
    Syntax error(missing operator) in query expression 'invoice.INVOICE_NO=inv_ent_main.INVOICE_NO INNER JOIN invrate ON invrate.INVOICE_NO=inv_ent_main.INVOICE_N'.
    My Query is-
    "select inv_ent_main.EXPORTER,inv_ent_main.INVOICE_NO,inv_ent_main.INVOICE_DATE,inv_ent_main.BALE_COUNT,inv_ent_main.TOTAL_AMOUNT,inv_ent_main.BALE_COUNT,inv_ent_main.TOTAL_PIECES,inv_ent_main.TOTAL_AREA,invoice.ORDER_NO,invoice.OTHER_REF,invoice.CONSIGN1,invoice.CONSIGN2,invoice.CONSIGN3,invoice.CONSIGN4,invoice.CONSIGN5,invoice.DLV_TERMS,invoice.PAYMENT_TERMS,invoice.PRE_CARRIAGE,invoice.PR_CARRIER,invoice.DESTINATION,invoice.COUNTRY_DESTINATION,invoice.VESS_FLIGHT,invoice.PORT_LOAD,invoice.PORT_DSCH,invoice.MARK1,invoice.MARK2,invoice.CURRENCY,invoice.GOODS_DESCRIPTION,invoice.CFB,invoice.GROSS_WEIGHT,invoice.NET_WEIGHT,invoice.WOOL,invoice.COTTON
    from inv_ent_main INNER JOIN invoice ON invoice.INVOICE_NO = inv_ent_main.INVOICE_NO INNER JOIN invrate ON invrate.INVOICE_NO = inv_ent_main.INVOICE_NO";
    MCA,LUCKNOW.

    The last character in the error message has missing "O" when compare to the actual query you have posted. Please rerun it an verify or you can try the below query. You need to post DDL for all the 3 tables so that we can test.
    select
    inv_ent_main.EXPORTER,
    inv_ent_main.INVOICE_NO,
    inv_ent_main.INVOICE_DATE,
    inv_ent_main.BALE_COUNT,
    inv_ent_main.TOTAL_AMOUNT,
    inv_ent_main.BALE_COUNT,
    inv_ent_main.TOTAL_PIECES,
    inv_ent_main.TOTAL_AREA,
    invoice.ORDER_NO,
    invoice.OTHER_REF,
    invoice.CONSIGN1,
    invoice.CONSIGN2,
    invoice.CONSIGN3,
    invoice.CONSIGN4,
    invoice.CONSIGN5,
    invoice.DLV_TERMS,
    invoice.PAYMENT_TERMS,
    invoice.PRE_CARRIAGE,
    invoice.PR_CARRIER,
    invoice.DESTINATION,
    invoice.COUNTRY_DESTINATION,
    invoice.VESS_FLIGHT,
    invoice.PORT_LOAD,
    invoice.PORT_DSCH,
    invoice.MARK1,
    invoice.MARK2,
    invoice.CURRENCY,
    invoice.GOODS_DESCRIPTION,
    invoice.CFB,
    invoice.GROSS_WEIGHT,
    invoice.NET_WEIGHT,
    invoice.WOOL,
    invoice.COTTON from inv_ent_main
    INNER JOIN invoice ON invoice.INVOICE_NO = inv_ent_main.INVOICE_NO
    INNER JOIN invrate ON invrate.INVOICE_NO = inv_ent_main.INVOICE_NO
    Regards, RSingh

  • How to get data from three tables (A,B,C) having one to many relation between A and B .and having one to many reation between b and c

    i have  three tables A,B,C.  there is one to many relation between A and B. and one to many relation existed between table b and c . how will get data from these three tables

    check if this helps:
    select * --you can always frame your column set
    from tableA a
    left join tableB b on a.aid=b.aid
    left join tableC c on c.bid=b.bid
    This is just a general query. However, we can help you a lot more, if you can post the DDL + sample data and required output.
    Thanks,
    Jay
    <If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'>

  • Getting no result by joining three tables in BMM

    Hi all,
    I have a requirement where I have a fact table and two ailas dimension table.
    Let say fact is w_account_f and dimension ailas dim_w_account_d_trans and dim_w_account_d_sal of w_account_d table
    I have join in physical layer
    w_account_f ----> dim_w_account_d_trans with forgin key join
    w_account_f ----> dim_w_account_d_sal with forgin key join
    In BMM i have join these three table but given content level filter in dimension like
    dim_w_account_d_trans.tans_col = 'active'
    dim_w_account_d_sal.sal > 4000
    when i am trying to pull the report from all three table
    w_account_f, dim_w_account_d_trans, dim_w_account_d_sal
    its not giving any result where as when i trying to pull report with fact any one dimension its giving me result.
    can anyone help me in finding the soulting how to get the data by joining all these three tables.

    Hi,
    Take the physical query with all three tables selected. Run the query in sql developer, remove the joins one by one and check where it fails. Modify the rpd model accordingly.
    Regards,
    Dpka

  • SQL Server 2012 Three Tables Joining

    I have Three Tables in sqlserver2012
    Master Table
    OrderID       PackageID      CustomerName
    1                          1               Abc
    2                          2                Bcd
    3                          1                xyz
    Child1 Table
    OrderID         ControlName
    1                   Row1COlumn1             (It Means Pant in Red Color is selected by user(relation with Child2 Table))
    1                   Row3Column1             (It Means Gown in Blue Color is selected by user(relation with Child2 Table))
    1                   Row4Column3             (It Means T Shirt in White Color is selected by user(relation with Child2 Table))
    2                    Row1Column2            (It Means Tie in Green Color is selected by user(relation with Child2 Table))
    2                   Row3Column1             (It Means Bow in Red Color is selected by user(relation with Child2 Table))
    Child2 Table
    PackageID      Product      Color1     Color2    Color3
    1                       Pant        Red          Green     Blue                          
    (Row1 of Package 1)
    1                       Shirt        Blue           Pink    Purple  
    (Row2 of Package 1)
    1                       Gown       Blue          Black    Yellow                          
    (Row3 of Package 1)  
    1                       T Shirt      Red          Green     White                          
    (Row4 of Package 1)
    2                       Tie           Red            Green  
      White                         
    (Row1 of Package 2) 
    2                       Socks       Red          Green     White                         
    (Row2 of Package 2) 
    2                       Bow         Red          Green     White                         
    (Row3 of Package 2) 
    I want to have result like
    OrderID    PackageID      CustomerName   Pant    Gown     T Shirt      Tie           Bow   
    1                     1                      ABC      
               Red       Blue      White       x                x
    2                      2                      Bcd                
      x           x           x             Green        Red
    Waiting for solution.
    Thanks and Best Regards Umair

    For PIVOTing you can use PIVOT or CASE expression.
    CASE expression PIVOT (cross tabulation):
    http://www.sqlusa.com/bestpractices/training/scripts/casefunction/
    You can make both CASE & PIVOT dynamic:
    http://www.sqlusa.com/bestpractices2005/dynamicpivot/
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Querying unjoined tables

    Hi,
    In my physical layer, I have five tables.
    Here's how they are joined:
    Table A-->Table B-->Table C-->Table D-->Table E
    In the BMM layer, I have 3 Logical Tables 1 Fact Table.
    Logical Table A --> Fact.
    Columns from Table B and Table C are mapped to single logical table (with two LTS), let's say Logical Table B.
    Columns from Table D and Table E are mapped to single logical table (with two LTS), let's say Logical Table C.
    So, here is the BMM Layer set up:
    Logical Table A --> FACT
    Logical Table B --> FACT
    Logical Table C --> FACT.
    I am trying to query columns from Logical Table A and Logical Table C and I am not getting the correct results.
    Any ideas?
    rkingmdu

    What is the logical table source and physical table of your fact table?
    I think you should model it like this:
    Logical table A: 1 LTS having three tables: Physical Table A, B and C, joined by inner joins.
    Logical table B: 1 LTS having two tables: Physical Table B and C, joined by inner joins.
    Logical table C: 1 LTS having two tables: Physical Table D and E, joined by inner joins.
    Fact table Fact: 1 LTS having one table: Physical Table D.
    Regards,
    Stijn

  • Select three tables data with Same where condition

    Hi i want sum data in three tables with same where condition. how can i do this code very simple.
    SELECT SUM(SIGNA) FROM dbo.tblPLAG 
    WHERE   VERSION='ACTUAL' AND STATS='ST_Z010'
    AND FACILITY='FA_2003'
    AND  TD IN  ( SELECT TIMEID FROM Time   WHERE   ID BETWEEN 
     @YEAR+'.'+(SELECT RIGHT ('000'+ CAST (@PERIOD-6 AS varchar), 3)) 
     AND   
    @YEAR +'.'+(SELECT RIGHT ('000'+ CAST (@PERIOD AS varchar), 3)))
       

    Try following
    SELECT SUM(t1.SIGNA) + sum(t2.SIGNA) + sum(t3.SIGNA) and you query, it will add the SUMs of each table.. hopefully it will work

  • To combine three tables

    Hi,
    I am Meena.
    I am doing a project using NetBeans and MS-Access.
    Now I need to combine three tables.
    I take all the values from table3 and check with table2,table1 and get the result.
    Can you tell me some lines about this?
    That will helpful me to develop the query?
    Thank you so much.
    Meena.

    Hi,
    Good morning,
    thank you so much for your reply.
    I am Meena.
    In my project I need to access three tables from MS-Access.
    I table contains Scode,Sname.
    II table contains Ecode,ename.
    III table contains Scode,Ecode,Score.
    Now I want Scode,Ecode,Score from third table,
    Sname from I table for only the Scode which are in III table,
    Ename from II table for only the Ecode which are in III table.
    I try the following.
    select * from Student-File INNER JOIN Student-Exam-File ON Student-File.student-code=Student-Exam-File.student-code INNER JOIN Exam-File ON Exam-File.exam-code=Student-Exam-File.exam-code";
    I got the error .
    Syntax error in FROM clause.
    will you please help me to solve this.
    Thank you,
    Regards,
    Meena.

  • Hyperion Explorer 8.3 querying multiple tables that contain a specific item

    I have 3 annual tables that contain data for 3 different years.  Each table has a sale amount, item sold, and customer ID.  I want to pull a specific customer ID from all 3 tables at once. 
    Is there a way to achieve this?
    Thanks!
    Johnny

    Add the 3 fields from the first table, then click Query > Append Query, then add the same 3 fields in the same order from the second table, then add the same 3 fields in the same order from the third table.  This creates a UNION between the three tables; which means they need to be in the same order and have the same datatype.
    If you want to show duplicate data found in the different sources, just change the UNION operator to a UNION ALL operator, otherwise it will suppress any duplicate rows.
    To limit the data to one specific customer ID, you can set a limit on each of the UNION tabs with 'Customer ID = <selection>'.
    Good luck!
    Jarod Vierstra

  • How to join three tables?

    I have used this query to join three tables but it displays an error : field vbak-vbeln is unknown.
    please help me out..
    SELECT vbak-vbeln vbak-bstnk vbap-matnr vbap-zmeng makt-maktx
    INTO CORRESPONDING FIELDs OF TABLE itab FROM vbak
    inner JOIN vbap ON vbak-vbeln eq vbap-vbeln
    inner JOIN makt ON vbap-matnr eq makt-matnr
    WHERE vbak-bstnk = s_bstnk.

    Hi mohan kumar ,
    just follow the Syntax
    SELECT FLD1 FLD2 FLD3 FLD4 FLD5 INTO CORRESPONDING FIELDS OF TABLE ITAB FROM TABLE1 INNER JOIN TABLE2 ON
    TABLE1FLD1 = TABLE2FLD1 INNER JOIN TABLE3 ON TABLE2FLD2 = TABLE3FLD2 INNER JOIN TABL4 ON  TABLE3FLD3 = TABLE4FLD3
    WHERE FLD1 = 'AA'
    Hope this may be helpful.
    Please reward points if found ok.
    Thanks and regards,
    Rajeshwar.

Maybe you are looking for

  • How to map Boolean Types in Import Manager

    Hi, I have a issue in Import Manager for mapping Boolean Types. I have a field which has a single KEY and multilple values(for different languages). I want to map it to a field in a Tuple. I can map the Key to field name. But the values, I am not abl

  • Multiple Feedback Messages in Quiz Results

    Hello Everyone, I am sure I have seen the answer here somewhere, but I cannot find it now. So, here is my situation.... I am using Captivate 5.5 I have a 30 question quiz that covers 5 different topics.  I want the results page to give feedback speci

  • Lost Display to Panasonic TV

    I have just lost the display to my 38" Panasonic TV using the DVI - SVideo cable/adaptor. I can still view the MAC when connected to a monitor though! Any ideas how I can get the display back on my TV? Also can I connect using DVI-to component? Thank

  • Cheque print thru F-48 Downpayment to Vendor

    Hello Experts, Business Scenario : I m have to make just 1 or 2 down-payment to Vendors, for this i need not run Auto Payment Program. However, i wish to provide those Vendors with a print cheque thru the system (like that of F-58). please help how d

  • Help with Group By on SQL statement

    Iu2019m trying to group by Item Code in the following query, however, I keep receiving the following error message.  Do you know why? Msg 306, Level 16, State 2, Line 1 The text, ntext, and image data types cannot be compared or sorted, except when u