Random select using multiple tables

Hello World!!!
I'm trying to fix a form I modified last month and it's causing me fits!
I need to add another validation element (email address) to my password validation Form. The problem lies in the fact that I can't simply add an additional SELECT Statement to the query because it won't randomly select the same number that the first one did (records won't match). When I try to JOIN on the tables inside the inner SELECT, basically the same thing happens. I get an a result for the "e-mail" column but it doesn't match the same record as the first two.
Is there an easier way of doing this??? Here's the code I'm using that works for my first two column returns (from the agent_sec_questions Table). I'm trying to add one more column (email) from the agent_data Table.
Thanks in advance for any suggestions.
SELECT security_question, question_number
FROM (SELECT security_question, question_number
FROM agent_sec_questions
WHERE agent_id =
(SELECT agent_id
FROM agent_data
WHERE username = 'john doe')
ORDER BY DBMS_RANDOM.VALUE (1, 9))
WHERE ROWNUM = 1;

Here's the solution I came up with if interested. I got the random number first, then joined my tables. If you have a better one, please let me know...
Chow!
M
SELECT DBMS_RANDOM.VALUE(1,3) INTO Sel_Num FROM DUAL;
MESSAGE ('Sel_Num= '||Sel_Num||' ID= '||UPPER(:LOGON_BLOCK.USERID));
pause;
               SELECT b.email, a.security_question, a.question_number
               INTO L_email, L_sec_q, L_q_num
          FROM lookup.agent_sec_questions a, lookup.agent_data b
          WHERE b.agent_id = a.agent_id
          AND b.username = TRIM(UPPER(:LOGON_BLOCK.USERID))
          AND a.question_number = sel_Num
               AND ROWNUM = 1;

Similar Messages

  • Selecting from multiple tables, into one internal table

    Hi,
    What is the best & most efficient method of selecting from multiple table (in my case 6,) into one internal table?
    Thanks,
    John
    Points will be rewarded and all responses will be highly appreciated.

    I have simple example :
    First one - Join 5 tables
    data : f1 type i,
              f2 type i,
              f3 type i.
    start-of-selection.
    get run time field f1.
    write the query 4 or 5 tables join.
    get run time field f2.
    f3 = f2 - f1 ( Total time).
    Second one - joins 3 table and use for all entries
    data : f1 type i,
              f2 type i,
              f3 type i.
    start-of-selection.
    get run time field f1.
    write the query 3 tables join and use for all entries
    get run time field f2.
    f3 = f2 - f1. ( Total time )
    Finally you can have time diffrence between the both sql statement.

  • How to use multiple table in single control file?

    Hi,
    How to use multiple table and data file in sigle control file? I have a four table and four csv file i mean data file for that. I am running concurrent program to load the data from csv file to custom table. based on my input data file name, it has to take automatically from one control file.
    Can anyone share with me how can i acheive this?
    Thanks

    Hi,
    Can't we acehive like below. I don't this exactly corrcect.
    OPTIONS (SKIP=1)
    LOAD DATA
    INFILE << file name 1 >>
    APPEND INTO TABLE XXCZ_VA_SAMPLE1
    FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS
         PARENT_ITEM               "TRIM(BOTH FROM :PARENT_ITEM)"
    LOAD DATA
    INFILE << file name 2 >>
    APPEND INTO TABLE XXCZ_VA_SAMPLE2
    FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS
         ITEM_NUMBER               "TRIM(BOTH FROM :ITEM_NUMBER)"
    )Edited by: orasuriya on Sep 14, 2009 3:03 AM

  • Using table comparison can we use multiple tables as source?

    Using table comparison can we use multiple tables as source?
    Thank you very much for the helpful info.

    Table Comparison
    1) Input Data coming in
    2) Comparison table (table to which the data is compared)
    3) Output (input rows with respective opcodes based on the comparison result of input dataset with the comparison table)
    If your question is whether table comparison can accept union/join of multiple table sources, you can achieve by using merge/query transforms and then feeding to table comparison. Here, you have to be careful about choosing the primary keys inside table comparison

  • Writeback using Multiple tables

    Hello Everyone,
    1. Can we create a report with writeback capabilities using Multiple tables (Say one fact and several dimensions)?.
    Whatever examples I'm seeing in blogs or forums with screesnshots , explains writeback Reports created with just one table.
    2. If writeback can work with reports using multiple tables, how do we need to change the XML scripts in custom message folder(insert and update)?
    any example ?
    Your suggestions are appreciated.
    Thanks

    You can only send one statement. Then if you want update many tables, you have to use a procedure/function in your SQL statement. For instance with a table function:
    http://gerardnico.com/wiki/database/oracle/table_function
    But I will advice you to do it with the simplest way possible: then one answer for one table to update.
    Success
    Nico

  • Using radio button selection in multiple tables

    Hello All,
    I've got a bit of a design issue and it being a Friday my brain is a bit foggy and I can't seem to figure out a solution.
    what I want to do is have 3 tables. The user should only be able to select one line from any of the three tables.
    I can do this by having events that clear down selection on the two other tables on any selection of the third, but the select buttons of tables don't really give the UI impression that only one row can be selected. To do this I'd like to use the radio button element.
    so
    table A
    choice - name
    (o) - Anne
    (o) - Bob
    (o) - Charlie
    Table B
    choice - name
    (x) - David
    (o) - Ellen
    (o) - Fran
    Table C
    choice - name
    (o) - George
    Here the entry in table B for David is selected. But any selection of any of the other options should deselected.
    My thoughts are to use a radio button ui element, bind the "selected" value to a unique id for each row/table (an attribute of the node element for each table) and the value to a common shared attribute (not table specific).
    Any better ideas - and certainly any which would mean I'm not going to have to maintain a lookup table of my unique ids and node elements to find out which one is selected?
    Cheers,
    Chris

    Ok - here's how I did it.
    I created another lookup table which had a guid and reference to the element.
    in the each elements I had a guid which I bound to the key for selection property of the radio button in the table.
    I then bound the selected key property to an attribute that was common to all elements.
    in my "processing" logic I read the selected key, read the lookup table - and therefore got the reference to the selected element.
    Would have been an awful lot easier if I could have used a reference to the element itself as the "key" - but that was required to be a character field.
    [image showing radio button selection working across multiple tables|http://i51.tinypic.com/bi79dx.jpg]
    End result works quite nicely.
    Cheers,
    Chris

  • Left outer join using multiple table

    Hi,
    I am trying to use left outer join with multiple tables , the join condition will be based on  PERNR and BEGDA & ENDA for each infotype in selection screen.
      select pa00~pernr pa00~begda pa00~endda pa00~massn pa00~massg pa00~stat2 pa00~aedtm pa00~uname
        pa01~begda pa01~endda pa01~bukrs pa01~persg pa01~persk pa01~mstbr pa01~ename pa01~aedtm pa01~uname
        pa02~begda pa02~endda pa02~nachn pa02~vorna pa02~midnm pa02~aedtm pa02~uname
        pa016~begda pa016~endda pa016~cttyp pa016~aedtm pa016~uname
        into CORRESPONDING FIELDS OF TABLE i_pall
        from  ( PA0000 as pa00 left OUTER JOIN pa0001 as pa01 on pa00~pernr = pa01~pernr )
        left OUTER JOIN pa0002 as pa02 on pa00~pernr eq pa02~pernr )
        left OUTER JOIN  pa0016 as pa016 on pa00~pernr eq pa016~pernr )
        where pa00~pernr in S_pernr
        AND pa00~begda in s_bg0000
        and pa00~endda in s_nd0000.
    but this fails  to fetch the value of begda enda from each pa0000,pa0001,pa0002,pa0016.
    Please help!
    Monirul

    Why don't you use the standard logical database PNPCE and then Provide statement?

  • How to use multiple tables in DRIVING_SITE

    Hi All,
    I see very bad performance with my query having dblinks to remote database.
    How can I use DRIVING_SITE for multiple remote tables here?
    Does it it useful to use on DRIVING_SITE multiple tables?
    What is impact of using ORDER BY on local table column ( table A in below case) in the query?
    SELECT A.col1, B.col2 , C.col3
    FROM A, B@dblink1, C@dblink1, D@dblink2
    WHERE <few join conditions>
    ORDER BY A.col1 ;
    Join conditions in above query is taken care to have better performance. But from our analysis it is understood that poor performance is due to DB Links to remoate database. What is best approach to get good performance with DB Links?
    Regards,
    Ram

    http://download.oracle.com/docs/cd/E11882_01/server.112/e17120/ds_appdev004.htm#ADMIN12196
    Will give you an idea of where to start.

  • Row selection across multiple tables

    Hi
    I currently have multiple tables where, if the user selects a particular row or group of rows in one table the correspondign row or group of rows is selected in the other table.
    At the moment I've acheived this by placing listSelection listeners on all the tables so that when the selection on one table changes it fires an event and updates the slection on the other tables using:
    secondTable.setRowSelectionInterval(
    firstTable.getSelectedRows()[0],
    firstTable.getSelectedRows()[firstTable.getSelectedRowCount() - 1]
    );This works fine if the user selects a single row or a continuous group of rows. THe problem is if the user selected a non-continuous group, or selects a continuous group and then deselects some of these rows.
    Because the method I've got selects all rows between the start and finish of the selection it means rows are highlighted on the other tables that are not highlighted on the first table.
    My thoughts on how to approach this would be to cycle through the array of selected rows and select the corresponding rows in the other tables individually rather than selecting a range, but I can't see how to accomplish this. Could anyone give me some pointers or suggestions.
    Thanks

    What you are doing is correct in principle (use a
    listener to propagate the selection)
    Always a good start :-)
    but you need to
    understand the subtleties of the ListSelectionEvent -
    read the API carefully - it gives you a range of
    indices which may have changed but does not tell you
    whether any specific indices in that range are
    selected or unselected.
    That makes sense, the event just indicates that the selection has changed yes?
    For that you will need to get
    the source ListModel from the event and query each
    row in the event range to determine its selection
    state.
    This is where I run into difficulty. I think I can go through the each row and find out if its selected or not (using isSelectedIndex(i))
    What I'm unsure what to do is how to set that for the rows in the other ListModels. What I would have normally done would be something like
    otherListModel.getIndex(i).setSelected(firstListModel.isSelectedIndex(i));But as the api doesnt list the methods to do that I think I might not have got this concept sorted in my head. Could someone provide me with some pointers?
    Thanks

  • Reports using multiple tables

    I am trying to create a report using portal that use links between multiple columns. The info I want is mainly in two tables. Some of the info in the table is numeric (Foreign Keys). I want to display them in readable format so set up joins to the respective parent tables. When I do this the result only produces 12 lines of output irrespective of the number of lines I set per page. When I show only the data from the main tables, without the joins to the other parent tables, i.e. the foreign keys as numbers I get all the rows. I have tried to create the report by using all three options given but get the same result.
    I am using 9iAS verison 1.0.2.0 and Portal version 3.0.7.
    Can someone please explain why this happens and how I can solve this problem urgently.

    Hi Ashok,
    Sorry for posting the solution with delay. Actually I ran into the similar situation and upon deep analysis, I could crack it., the very next day.
    This is how your write back template should be for updating on multiple tables
    <?xml version="1.0" encoding="utf-8" ?>
    <WebMessageTables xmlns:sawm="com.siebel.analytics.web/message/v1">
    <WebMessageTable lang="en-us" system="WriteBack" table="Messages">
    <WebMessage name="WRITE">
    <XML>
    <writeBack connectionPool="Oracle Data Warehouse Connection Pool">
    <insert> </insert>
    <update> UPDATE FACT SET COUNT = '@{c4}', W_UPDATE_DT = CURRENT_DATE
    WHERE EXISTS (SELECT ROW_WID FROM DIM WHERE DIM.ROW_WID = FACT.DIM_WID AND
    DIM.X = '@{c1}' AND DIM.Y= '@{c2}' AND DIM.Z = '@{c3}' ) AND EXISTS (SELECT ROW_WID FROM DT WHERE DT.ROW_WID = FACT.DT_WID AND DT.PER_NAME_YEAR = '@{c0}') </update>
    </writeBack>
    </XML>
    </WebMessage>
    </WebMessageTable>
    </WebMessageTables>
    =====
    Using exits, will improve the performance.
    Hope it helps. If yes, pls award points. Thanks
    Regards,
    Sarat Nallapati

  • Select from multiple tables without join statement

    Hey Gurus,
    I would like to make a select from a multiple tables to check if there is any reference to my data. I would like to do it with some elegancy, but I don't know how.
    Is in abap sql possible to do it only with the select statement?
    Or I was also think about a solution that I should fill some data structure with all of the tables which I want to select from and then just loop that data structure and do the select seperately from all of the tables. I just need to check if it founds some results, so no need to store it. If this solution would be fine what data structure should I use?
    Or can tell me what would be the best for this?
    My code for select from one table, which I want to make for multiple tables:
    SELECT SINGLE id_kniznice FROM zbr_t_autori INTO wa_id
           WHERE id_kniznice EQ ls_extract-zview-id_kniznice.
         IF sy-dbcnt > 0.
           MESSAGE i000(zbr_msgc_lib).
           ls_extract-flags-vim_mark = '*'.
           MODIFY extract FROM ls_extract.
    ENDIF.   
    Thank you for any posts.
    Regards,
    Robert

    And there we go again...
    Read this topic:
    For All Entries is NOT better than INNER JOIN in most cases
    And this one:
    inner join vs for all entries
    Also that one:
    Re: LOOP AT vs INNER JOIN
    JOINs are really better than for all entries in most cases. Problem is people tend to ignore basic things like using pks or indexes while making them.

  • Dynamic select for multiple tables

    Hi Thanks for your reply.Can you please help me in this issue.
    I have a requirement like how to select data from multiple tables using dynamic select. How do we maintain dynamic where condition.
    Manohar.

    [How to write dynamic where clause|How to write a Dynamic Where clause]

  • Select from multiple tables through dblink

    I am seeking help. Can I select multiple tables through a dblink from a remote database? I tried, it seems it always return ORA-00933 error. code like this:
    select A.ID, B.CODE, C.TYPE_DESC
    from TABLE_ONE A@db_link , TABLE_TWO B@db_link, TABLE_THREE C@db_link;
    where A.ID = B.ID
    and B.CODE = C.CODE
    Thanks in advance.

    Just as an FYI, from a performance standpoint, it is frequently the case (though certainly not guaranteed) that you'll get better performance creating a view on the remote database that does the join of all three tables and to use that view in your query, particularly if you're also joining in local tables. Optimizing SQL statements across database links tends to be particularly hard, a view often helps force Oracle to join the remote tables on the remote database which is generally what you'd want. Of course, this is not a guarantee, and you can always get explicit with hints to force joins to happen on one or the other system, but this is frequently the easiest starting point.
    Justin

  • Sample PHP Service selecting from multiple tables

    Hi all!
    I have the following challange:
    How do I properly set up my PHP-service to insert, select, update and delete values from multiple tables?
    So far, the standard templates generated by Flash Builder is based on a single table.
    Example: I have 2 tables: [person] and [school]
    [person] has [person_id, first_name, last_name, birthdate]
    [school] has [school_id, person_id, school_name, city]
    One [person] can have multiple [schools]
    How should I define the selectByID function in PHP to be able to have
    First name: [TextInput /]
    Last name: [TextInput /]
    Birthdate: [DateField /]
    Schools:
    [TabBar: School1, School2, School3 /]
    [ViewStack1]
    School name: [TextInput /]
    Location name: [TextInput /]
    [/ViewStack1]]
    [ViewStack2]
    School name: [TextInput /]
    Location name: [TextInput /]
    [/ViewStack2]]
    [ViewStack3]
    School name: [TextInput /]
    Location name: [TextInput /]
    [/ViewStack3]]
    And even more interesting: How do I update all these fields back to the database?

    First, the relationship between school and person is many-to-many NOT one-to-many -- you will need to add a junction table.
    From the form you have given I would handle insertions like this:
    loop through all the schools and see if the school already exist in the DB. If so, then store the school_id. If not, then create a new record and store the id. You should have an array collection of store_ids by the end of the loop
    Check whether the student exists w/in the DB. If so, then you might consider aborting the operation or you could opt to do an update. If the student doesn't exist, then create a new student record and store the new student_id (mysql::insert_id)
    Loop through the school_id array and add new student_id/school_id records into the junction table.
    Retrieving records is much simpler -- it's just a join on the tables i.e. "SELECT * FROM student INNER JOIN school_student ON student.student_id = school_student.student_id INNER JOIN schools ON school_student.school_id = school.school_id WHERE student.first_name = 'John' AND student.last_name = 'Doe' (assuming there aren't more than one John Does of course!).
    - e

  • How to set aggregation rule (SUM) to a query which uses multiple tables

    Hi,
    I have a doubt like i have a query .i want to get the sum of few columns in that..how can i achieve it as it joins multiple tables . i am posting the query under this. please help me to resolve this. i need to get summation of column which is marked in bold . i am so sorry to post such a big query.. thanks in advance.
    SELECT DISTINCT
        SAS.ACCOUNT_MONTH_NO,
        SAS.BILL_TO_MAJOR_SALES_CHANNEL,
        SAS.BUS_AREA_ID,
        SAS.CUST_NAME,
        SAS.PART_NO,
        SAS.PART_DESC,
        SAS.PRODUCT_CLASS_CODE,
        SAS.SUPER_FAMILY_CODE,
        *SAS.NET_SALES_AMT_COA_CURR,* 
      *SAS.GROSS_SALES_AMT_COA_CURR*,
        *SAS.SHIPPED_QTY*,
        SAS.SRCE_SYS_ID,
        GWS.SRC_LOCATION,
        GWS.PART_CF_PART_NUMBER,
        GWS.ANALYST_COMMENTS,
        NVL(GWS.CLAIM_QUANTITY,0) AS *CLAIM_QUANTITY*,
        GWS.CUSTOMER_CLAIM_SUBMISSION_DATE,
        GWS.CLAIM_TYPE,
        GWS.CREDIT_MEMO_NO,
        NVL(GWS.CREDIT_MEMO_AMT,0) AS *CREDIT_MEMO_AMT*,
        GWS.TRANS_CREATED_BY,
        GWS.COMPONENT_CODE,
        GWS.DATE_OF_THE_FAILURE,
        GWS.DATE_PART_IN_SERVICE,
        GWS.PROBLEM_CODE,
        NVL(GWS.TOT_AMT_REVIEWED_BY_CA,0) AS *TOT_AMT_REVIEWED_BY_CA*,
        GWS.REGION
      FROM
    SELECT
            TO_CHAR(A.STATUS_DATE, 'YYYYMM') AS ACCOUNT_MONTH_NO,
            A.LOCATION_ID SRC_LOCATION,
            A.CF_PN PART_CF_PART_NUMBER,
            A.ANALYST_COMMENTS,
            A.CLAIM_QUANTITY, 
         A.CUST_CLAIM_SUBM_DATE CUSTOMER_CLAIM_SUBMISSION_DATE,
            A.CLAIM_TYPE,
            A.CREDIT_MEMO_NO,
            A.CREDIT_MEMO_AMT,
            A.CREATED_BY TRANS_CREATED_BY,
            A.FAULT_CODE COMPONENT_CODE,
            A.PART_FAILURE_DATE DATE_OF_THE_FAILURE,
            A.PART_IN_SERVICE_DATE DATE_PART_IN_SERVICE,
            A.FAULT_CODE PROBLEM_CODE,
            A.TOT_AMT_REVIEWED_BY_CA,
            A.PART_BUS_AREA_ID AS BUS_AREA_ID,
            A.PART_SRC_SYS_ID,
            C.CUST_NAME,
            C.BILL_TO_MAJOR_SALES_CHANNEL,
            P.PART_NO,
            P.PART_DESC,
            P.PRODUCT_CLASS_CODE,
            L.REGION
          FROM
            EDWOWN.MEDW_BIS_DTL_FACT A,
            EDWOWN.EDW_MV_DB_CUST_DIM C,
            EDWOWN.EDW_BUSINESS_LOCATION_DIM L,
            EDWOWN.EDW_V_ACTV_PART_DIM P
          WHERE
            A.PART_KEY                       = P.PART_KEY
          AND A.CUSTOMER_KEY                 = C.CUSTOMER_KEY
          AND A.LOCATION_KEY                 = L.LOCATION_KEY
          AND A.PART_SRC_SYS_ID              = 'SOMS'
          AND A.PART_BUS_AREA_ID             = 'USA'
          AND C.BILL_TO_MAJOR_SALES_CHANNEL <> 'IN'
        GWS,
          SELECT
            A.ACCOUNT_MONTH_NO,
            A.BUS_AREA_ID,
            A.NET_SALES_AMT_COA_CURR,
            A.GROSS_SALES_AMT_COA_CURR,
            A.SHIPPED_QTY,
            B.BILL_TO_MAJOR_SALES_CHANNEL,
            A.SRCE_SYS_ID,
            B.CUST_NAME,
            D.PART_NO,
            D.PART_DESC,
            D.PRODUCT_CLASS_CODE,
            D.SUPER_FAMILY_CODE
          FROM
            SASOWN.SAS_V_CORP_SHIP_FACT A,
            SASOWN.SAS_V_CORP_CUST_DIM B,
            SASOWN.SAS_V_CORP_LOCN_DIM C,
            SASOWN.SAS_V_CORP_PART_DIM D
          WHERE
                C.DIVISION_CODE = A.DIVISION_CODE
            AND
                B.B_HIERARCHY_KEY = A.B_HIERARCHY_KEY
            AND
                D.PART_NO = A.PART_NO
            AND
                A.SRCE_SYS_ID = 'SOMS'
            AND
                A.BUS_AREA_ID = 'USA'
            AND
                B.BILL_TO_MAJOR_SALES_CHANNEL <> 'IN'
        SAS
      WHERE
        SAS.ACCOUNT_MONTH_NO              = GWS.ACCOUNT_MONTH_NO(+)
      AND SAS.BILL_TO_MAJOR_SALES_CHANNEL = GWS.BILL_TO_MAJOR_SALES_CHANNEL(+)
      AND SAS.BUS_AREA_ID                 = GWS.BUS_AREA_ID(+)
      AND SAS.PRODUCT_CLASS_CODE          = GWS.PRODUCT_CLASS_CODE(+);thanks in advance
    aswin

    You get rid of the distinct.
    You put sum() around your starred items.
    You put all the remaining columns in a GROUP BY clause.
    You hope that that none of the other tables has more than one row that matches the SAS table, which would cause you to count that row more than once.

Maybe you are looking for

  • Having a problem in app store

    Hii guys whrn i tried to download apps from app store they are not downloading and showing the app as waiting and the updates are also not downloading plzzz help mee

  • Pass a value to a class that extends AbstractTableModel

    Hi I have a problem with a table model that I cannot find a way of overcoming. I have created a class called MyTableModel that extends AbstractTableModel. MyTableModel creates and uses another class that I have defined in order to retrieve records fr

  • SQL Server Log: Login failed for user ''

    We've found in SQL Server Log many records: Date 3/22/2013 11:13:03 AM Log Windows NT (Application) Source MSSQLSERVER Category Logon Event 3221243928 Computer SBO05 Message Login failed for user ''. Reason: An attempt to login using SQL authenticati

  • Dialer Watch List on Pri dialer????????

    Dear All, I have a 2811 router... In which I want to configure the dialer watch list.. Plz clarify which ip shud we put on dialer watch list...???? Is it the route . plz find the example below.. boot-start-marker boot system flash c2800nm-entbase-mz.

  • What would possess Apple to disable the Genius Function in iTunes 11

    I bought more great music that way than any other way possible. But now there are NO recommnedations from the iTunes store for the songs I owe. The first thing I always did after purchasing a new song was to see what the other recommendations were an