Join between 2 tables

All,
I am newbie to this forum.
A main query has a table say A along with other tables in a query. My requirement is to add a new table say D to fetch the records in the below fashion...
take grant_num from table A and join grant_num with table D and take deu_grant_num from same table D...Pass deu_grant_num from table D to table A and fetch the results with respect to the grant_num from table A...
Below are the table structures:
table A:
User_id, grant_num,...
Table B:
grant_num, deu_grant_num, user_id...
Appreciate ur help ASAP...

Try This Query
cursor abc is select grant_num from tableA
where grant_num in(select grant_num from tableB
where tableA.grant_num =tableB.grant_num)
begin
open abc;
ftech abc into :grant_num ;
close abc;
end;
or
select grant_num into grant_num from tableA
where grant_num in(select grant_num from tableB
where tableA.grant_num =tableB.grant_num)

Similar Messages

  • Find the key for join between table "crhd" and "equi" for use field "answt"

    I make program for read data from table "crhd" for print  about machine report
    but I can not find the key for link join to table "equi" for print field "answt" (acquistion value)
    please help me  find the key field for join between table "crhd" and "equi" for use field "answt"
    thank you very much...

    This is how the Work Center is linked to a particular Equipment -
    Functional - In IE03 ( view Equipments) You see the Work Center of a particular Equipment.
    Technical - Go to view V_EQUI ( view of EQUI and EQUZ). Pass the Equipment number alongwith V_EQUI-PM_OBJTY = 'A' ( i,.e searching for the Object Type Work Center).  In this way u ll get the V_EQUI-GEWRK - this is the Work Center ID.
    You can pass this Work Center ID to CRHD. And you will get the Work Center text.
    CRHD-OBJTY = 'A'
    CRHD-OBJID = V_EQUI-GEWRK.
    and u ll get the CRHD-ARBPL - this is the Work Center.
    So u need to come backwards, alongwith ur CRHD-OBJTY and CRHD-OBJID , you pass the same to V_EQUI and u get the list of equipment numbers alongwith ur ANSWT(Acquisition value).
    I guess it solves ur problem.

  • 1.1 query builder join between tables

    In the latest Sql Developer.
    I invoke the query builder and select multiple tables that have foreign keys between them. These foreign key relationships appear in the diagram (good job).
    How do I make those relationship appear in the SQL that query builder returns to the sql worksheet. I shouldn't have to re-specify them on the where/criteria tab.
    It would be nice if these relationships are defaulted in the joining of tables.

    I overlayed the pre-release versionsDo you mean you installed in the same directory?
    Don't do that.
    There's a system directory (sqldeveloper\sqldeveloper\system) which holds settings and everything, which very well might be corrupted to be used for a newer release.
    Try deleting it, it will be regenerated at next startup. Or even better: re-install in another directory all together...
    K.

  • ABAP query- unable to delete the join between tables

    Im unable to delete the join between two tables. when i right clicked on the join then it gives two options:
    1. Display join condition
    2. Remove join condition
    both these options are grey in color so i cant select them. how can i remove join?

    goto SQ02 and enter infoset and goto change mode agagin select change mode and click the join then select and delete link...

  • Dynamic SQL Joining between tables and Primary keys being configured within master tables

    Team , Thanks for your help in advance !
    I'm looking out to code a dynamic SQL which should refer Master tables for table names and Primary keys and then Join for insertion into target tables .
    EG:
    INSERT INTO HUB.dbo.lp_order
    SELECT *
    FROM del.dbo.lp_order t1
    where not exists ( select *
    from hub.dbo.lp_order tw
    where t1.order_id = t2.order_id )
    SET @rows = @@ROWCOUNT
    PRINT 'Table: lp_order; Inserted Records: '+ Cast(@rows AS VARCHAR)
    -- Please note Databse names are going to remain the same but table names and join conditions on keys
    -- should vary for each table(s) being configured in master tables
    Sample of Master configuration tables with table info and PK Info :
    Table Info         
    Table_info_ID    Table_Name    
    1        lp_order    
    7        lp__transition_record    
    Table_PK_Info        
    Table_PK_Info_ID    Table_info_ID    PK_Column_Name
    2                1    order_id
    8                7    transition_record_id
    There can be more than one join condition for each table
    Thanks you !
    Rajkumar Yelugu

    Hi Rajkumar,
    It is glad to hear that you figured the question out by yourself.
    There's a flaw with your while loop in your sample code, just in case you hadn't noticed that, please see below.
    --In this case, it goes to infinite loop
    DECLARE @T TABLE(ID INT)
    INSERT INTO @T VALUES(1),(3),(2)
    DECLARE @ID INT
    SELECT @ID = MIN(ID) FROM @T
    WHILE @ID IS NOT NULL
    PRINT @ID
    SELECT @ID =ID FROM @T WHERE ID > @ID
    So a cursor would be the appropriate option in your case, please reference below.
    DECLARE @Table_Info TABLE
    Table_info_ID INT,
    Table_Name VARCHAR(99)
    INSERT INTO @Table_Info VALUES(1,'lp_order'),(7,'lp__transition_record');
    DECLARE @Table_PK_Info TABLE
    Table_PK_Info_ID INT,
    Table_info_ID INT,
    PK_Column_Name VARCHAR(99)
    INSERT INTO @Table_PK_Info VALUES(2,1,'order_id'),(8,7,'transition_record_id'),(3,1,'order_id2')
    DECLARE @SQL NVarchar(MAX),
    @ID INT,
    @Table_Name VARCHAR(20),
    @whereCondition VARCHAR(99)
    DECLARE cur_Tabel_Info CURSOR
    FOR SELECT Table_info_ID,Table_Name FROM @Table_Info
    OPEN cur_Tabel_Info
    FETCH NEXT FROM cur_Tabel_Info
    INTO @ID, @Table_Name
    WHILE @@FETCH_STATUS = 0
    BEGIN
    SELECT @whereCondition =ISNULL(@whereCondition+' AND ','') +'t1.'+PK_Column_Name+'='+'t2.'+PK_Column_Name FROM @Table_PK_Info WHERE Table_info_ID=@ID
    SET @SQL = 'INSERT INTO hub.dbo.'+@Table_Name+'
    SELECT * FROM del.dbo.'+@Table_Name+' AS T1
    WHERE NOT EXISTS (
    SELECT *
    FROM hub.dbo.'+@Table_Name+' AS T2
    WHERE '+@whereCondition+')'
    SELECT @SQL
    --EXEC(@SQL)
    SET @whereCondition = NULL
    FETCH NEXT FROM cur_Tabel_Info
    INTO @ID, @Table_Name
    END
    Supposing you had noticed and fixed the flaw, your answer sharing is always welcome.
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • Multiple joins between tables

    Not sure that the title best describes this.
    I've got two tables which I'll simplify here
    t1 - building (BuildingCode, Reception, Porter, Manager)
    A, 1, 3, 8
    B, 2, 4, 9
    C, 1, 4, 7
    t2 - staff (ID, Name, Extn)
    1, Dave, 3302
    2, Chris, 3994
    3, Claire, 3033
    8, Simon, 3255
    and i'd like to get a table out that looks like
    A, Dave, 3302, Claire, 3033, Simon, 3255
    B, Chris, 3994 etc.
    select b.buildingCode, s.Name, s.Extn
    from building b, staff s
    where s.ID = b.Reception
    would give me one set of details - how can i get all 3?
    Do I need to do 3 queries - where s.ID = b.Reception, where
    s.ID = b.Porter and where s.ID = b.Manager and then join the 3
    tables together or is there a more direct route?
    Many thanks
    Michael

    Now that I've had a chance to try the code I found that to
    use the results on the page I needed aliases in the select part as
    well - final code is
    select t1.BuildingCode, r.Name as rname, r.Extn as rextn,
    p.Name as pname, p.Extn as pextn, m.Name as mname, m.Extn as mextn
    from t1, t2 r, t2 p, t2 m
    where t1.Reception = r.ID
    and t1.Porter = p.ID
    and t1.Manager = m.ID

  • Join between tables

    what is wrong :
    SELECT viser02~sdaufnr
       FROM (viser02  INNER JOIN vbak
                   ON vbakvbeln = viser02sdaufnr
                   AND vbakposnr = viser02posnr
                   INNER JOIN vbap
                   ON vbapvbeln = viser02sdaufnr
                   AND vbapposnr = viser02posnr)
        where vbak~auart = 'WV'
        and ( vbap~sobkz <> 'V'
              OR vbap~sobkz <> 'W' ).

    Hi,
    Write the join as follows
    DATA: BEGIN OF ITAB_AUFNR OCCURS 0,
            SDAUFNR LIKE VISER02-SDAUFNR,
          END OF ITAB_AUFNR.
    SELECT viser02~sdaufnr
      INTO TABLE ITAB_AUFNR
      FROM viser02
    INNER JOIN vbak
        ON vbakvbeln = viser02sdaufnr
    INNER JOIN vbap
        ON vbapvbeln = viser02sdaufnr
       AND vbapposnr = viser02posnr
    where vbak~auart = 'WV'
      and ( vbapsobkz <> 'V' OR vbapsobkz <> 'W' ).
    The problem with your join is in VBAK there will not be any item field(POSNR) and you also didn't specify the into clause.
    As a best practice do not use negative conditions in where cluases, they will consume more time. There will be two options to eliminate this.
    1. Populate ranges table with all the allowed values for the SOBKZ field and use it in where clause.
    OR
    2. Populate ranges table with the not required values with the sign option 'E' (Exclude).
    If you need any further help let me know.
    Thanks
    Giridhar

  • How To Find joins between siebel tables

    Hi Experts,
    I am new in siebel and i am working on BI reports.
    I need to write queries to fetch data from sibel database.
    Any idea how do we find joins between table in siebel. Is there any user guide??
    Cheers,
    Andy

    Hi Andy,
    We can find Joins in Object Explorer. Expand the Business Component Object in Object Explorer and you can find Join. In Siebel generally we use only Equi Joins. ROW_ID of parent table will be stored in PAR_ROW_ID of child table. ROW_ID and PAR_ROW_ID are the columns of the table. Most of the tables have these two columns.
    For Example: Take two tables S_CONTACT AND S_CONTACT_X, the ROW_ID of S_CONTACT will be stored in PAR_ROW_ID of S_CONTACT_X table.
    If you want to join these two tables the query will be like
    "SELECT * FROM S_CONTACT CON, S_CONTACT_X CONX WHERE CON.ROW_ID = CONX.PAR_ROW_ID"
    This query will return all the records from S_CONTACT_X which matches S_CONTACT table.
    Thanks & Regards,
    Vinodhkumar

  • Join multiple tables across separate databases

    I needed to perform a join on multiple tables in two separate databases. I am using Sybase ASE 12.5 and jConnect 5.5 JDBC driver.
    Table A is in DB1 and Table B is in DB2. Both DB1 and DB2 reside on the same database server.
    I have set up JNDI bound datasources DS1 for DB1 and DS2 for DB2.
    If the queries involved single tables or multiple tables within the same database, it is simple. But I am not seeing any way where I can perform a join between Tables A and B, which reside in separate databases. The datasources DS1 and DS2 are associated with DB1 and DB2 respectively, so I am not sure if there is anything like performing joins using two data sources.
    One alternative I am facing is using a stored procedure in one database refer the table in the other database, for the join. But I may not be allowed to modify the database; currently, I am allowed to perform READ-ONLY queries.
    So I am looking for any and all options. Please advice.
    Thanks!

    Two choices..
    One find the syntax in DB2 that allows you to do what you want in there. That would often be somelike...
    select a.myfield
    from database1.table1 a, database2.table2 b
    where a.id = b.id
    Obviously the database itself must support this. If it doesn't then you have choice two.
    You extract the data from database1 using java for table1.
    You extract the data from database2 using java for table2.
    You write java code that merges the data from both sources.

  • Join between Oracle and non-Oracle Database

    We are working at a project with the follow architecture:
    - 5 Databases (3 Oracle, 1 Sybase and 1 DB2);
    - Session Bean like Session Facade Pattern;
    - Entity Bean (BMP);
    - OC4J (Oracle Container for J2EE);
    The case is that we cannot make join between tables of different bases, for example, join with one table of Oracle and one other of DB2, therefore the customer does not possess tool midleware for this.
    The idea that appeared was: we make a query in table XXX of Oracle and return a HashTable with its respective VO�s and Keys (PKs from the first query that will serve of base for the second query), later we have access the DB2 that one second collection would return, to inside make join of the application.
    The problem is that with this solution, we will have fall in the performance. And we do not know if it is the best form.
    Do you have any idea???
    Thanks,
    Eric Sander

    Hi,
    If you have different databases then the join has to be done in the VM (either by the appserver or by you).
    If you want to do it yourself, I would try the following:
    -write one DAO per business object (at least one per database)
    -this DAO contains the specifics of its database
    -return a hashtable of keys and VOs from one DAO (as you say you do?)
    -in the other DAO, add a method "joinWith ( Hashtable foreignKeys )" that will return the join's result
    -implement the method along these lines:
    1. retrieve the candidate rows from the second DAO's tables (1 query execution)
    2. put the keys in a new Hashtable, say "candidateKeys" (meaning 1 iteration over all results)
    3. iterate over all elements of foreignKeys (1 iteration)
    4. for each element, check if a key exists in "candidateKeys" (1 hash lookup, very fast)
    5. add any such row to the result
    This is called a hash join (Oracle does it internally if you do a join).
    It is the fastest algorithm to do joins.
    Best,
    Guy
    http://www.atomikos.com - JTA transaction manager

  • Need help to join two tables using three joins, one of which is a (between) date range.

    I am trying to develop a query in MS Access 2010 to join two tables using three joins, one of which is a (between) date range. The tables are contained in Access. The reason
    the tables are contained in access because they are imported from different ODBC warehouses and the data is formatted for uniformity. I believe this cannot be developed using MS Visual Query Designer. I think writing a query in SQL would be suiting this project.
    ABCPART links to XYZPART. ABCSERIAL links to XYZSERIAL. ABCDATE links to (between) XYZDATE1 and ZYZDATE2.
    [ABCTABLE]
    ABCORDER
    ABCPART
    ABCSERIAL
    ABCDATE
    [ZYXTABLE]
    XYZORDER
    XYZPART
    XYZSERIAL
    XYZDATE1
    XYZDATE2

    Thank you for the looking at the post. The actual table names are rather ambiguous. I renamed them so it would make more sense. I will explain more and give the actual names. What I do not have is the actual data in the table. That is something I don't have
    on this computer. There are no "Null" fields in either of the tables. 
    This table has many orders (MSORDER) that need to match one order (GLORDER) in GLORDR. This is based on MSPART joined to GLPART, MSSERIAL joined to GLSERIAL, and MSOPNDATE joined if it falls between GLSTARTDATE and GLENDDATE.
    [MSORDR]
    MSORDER
    MSPART
    MSSERIAL
    MSOPNDATE
    11111111
    4444444
    55555
    2/4/2015
    22222222
    6666666
    11111
    1/6/2015
    33333333
    6666666
    11111
    3/5/2015
    This table has one order for every part number and every serial number.
    [GLORDR]
    GLORDER
    GLPART
    GLSERIAL
    GLSTARTDATE
    GLENDDATE
    ABC11111
    444444
    55555
    1/2/2015
    4/4/2015
    ABC22222
    666666
    11111
    1/5/2015
    4/10/2015
    AAA11111
    555555
    22222
    3/2/2015
    4/10/2015
    Post Query table
    GLORDER
    MSORDER
    GLSTARTDATE
    GLENDDATE
    MSOPNDATE
    ABC11111
    11111111
    1/2/2015
    4/4/2015
    2/4/2015
    ABC22222
    22222222
    1/5/2015
    4/10/2015
    1/6/2015
    ABC22222
    33333333
    1/5/2015
    4/10/2015
    3/5/2015
    This is the SQL minus the between date join.
    SELECT GLORDR.GLORDER, MSORDR.MSORDER, GLORDR.GLSTARTDATE, GLORDR.GLENDDATE, MSORDR.MSOPNDATE
    FROM GLORDR INNER JOIN MSORDR ON (GLORDR.GLSERIAL = MSORDR.MSSERIAL) AND (GLORDR.GLPART = MSORDR.MSPART);

  • Multiple 'logical joins' between a fact table and one dimension table

    It appears that one cannot create multiple ‘logical joins’ between a fact table and one dimension table in OBIEE using the Oracle BI Administration Tool. For example, considering a Business Model with a dimension table TIMES and a fact table FACT containing START_TIME and END_TIME, we would like to create separate logical joins from FACT to TIMES for the START_TIMEs and END_TIMEs? Obviously, the underlying foreign keys can be created, but as far as I can tell the Oracle BI Administration Tool doesn’t support this. The workaround would be to replicate the TIMES table, but that’s ugly.
    I seek an alternative approach.

    Try this. Create an two aliases for the TIMES dimension (Start & End) in the Physical Layer and then remove foreign key to the "Parent" Times dimension. Create the Foreign Key in the Physical Layer to the new aliases and then create the complex joins in the BMM Layer to the new aliases as well. This will allow you to present both dates within the same table in the Presentation Layer. Not the most elegant solution but it works.

  • Can we apply join between two internal tables?

    Itab has fields A,B,C.
    Data: begin of itab occurs 1,
             A  type I,
             B type I,
             C type I,
             End of itab.
    Jtab has fields A, I, J.
    Data: begin of itab occurs 1,
             A  type I,
             I type I,
             J type I,
             End of itab
    The common field between itab and jtab is u201CAu201D.
    Now I need to collect A,B,C,I, J in another internal table ktab.
    How should I be doing this.
    If I use a SELECT query with inner join between itab and jtab it says u201Citab is not a database tableu201D.
    How should I get the result  ktab with A B C I J fields?
    Please help, nay help will be highly appreciated?

    a®s wrote:
    >
    > sort itab_all by A
    > delete adjacent duplicates from itab_all comparing A.
    >
    >
    Do you have the above code in ?
    Here A is common field between both tables, first we are appending itab_1 & itab_2 into table itab_all then deleting the adjacent duplicates from itab_all. then we are reading itab_1 & itab_2 for possible matches and update the same values in itab_all
    so there will NOT be a chance of duplicates in itab_all

  • Abap query, join between same tables

    Hi,
    I have an Abap Query (SQ01), I need to create a join between the same table (ESLL-ESLL) to obtain the services from a PO. The join is with the packno from ESLL to subpackno from ESLL (the same table). But I don't know how I can do that with Abap Query. Because the Infoset doesn't allow inserting the table two times.
    Somebody can help me.
    Thanks.
    Victoria

    Hi:
    I was able to create a query to retrieve the service lines entries using tables ESSR (Header) (service entry sheet number as input parameter), linked to package number to view ML_ESLL and then from the view the sup-package number linked to ESLL. That way I was able to retrieve all the service lines information from table ESLL only using SQ02 and SQ01, no ABAP.
    I Hope this help.
    Juan
    PS: I know the post is old but may be there are people out there with no ABAP access who needs to create reports for Service Entry Sheets lines. All the join conditions are.
    Table             Table
    ESSR            EKKO
    ESSR            ML_ESLL
    ML_ESLL      ESLL
    ESLL             ESLH
    Edited by: Juan Marino on Jan 23, 2012 10:53 PM

  • How to provide joins between oracle tables and sql server tables

    Hi,
    I have a requirement that i need to generate a report form two different data base. i.e Oracle and Sql Server.
    how to provide joins between oracle tables and sql server tables ? Any help on this
    Regards,
    Malli

    user10675696 wrote:
    I have a requirement that i need to generate a report form two different data base. i.e Oracle and Sql Server. Bad idea most times. Heterogeneous joins do not exactly scale and performance can be severely degraded by network speed and b/w availability. And there is nothing you can do in the application and database layers to address performance issue at the network level in this case - your code's performance is simply at the mercy of network performance. With a single glaring fact - network performance is continually degrading. All the time. Always. Until it is upgraded. When the performance degradation starts all over again.
    If the tables are not small (few 1000 rows each) and row volumes static, I would not consider doing a heterogeneous join. Instead I would rather go for a materialised view on the Oracle side, use a proper table and index structure, and do a local database join.

  • Outer join between logical tables

    Hello,
    This question is likely to be asked many times, but I failed to find the proper thread in the forum.
    Assume there are 2 logical tables "Fact" and "Dim".
    "Fact" has 1 LTS which consists of physical tables F, FX1, FX2 which are inner joined.
    "Dim" has 1 LTS which consists of physical tables D, DX1, DX2 which are inner joined.
    F and D tables are also joined together on physical layer.
    I define left outer join between "Fact" and "Dim" on logical layer.
    I create a request in Answers, querying columns from "Fact" and "Dim" which map to physical tables F and D only.
    I expect OBIEE to build SQL query which uses F and D tables only, outer joined.
    Instead of that all the physical tables used for logical tables "Fact" and "Dim" are joined together in a form like:
    SELECT F.col, D.col
    FROM (F inner join FX1 inner join FX2) left outer join (D inner join DX1 inner join DX2)
    Is there any way to avoid this behavior or build data model in different way?
    Thank you!

    Hi Alex,
    In BI Applications you never have a null in a facts foreign key to the dimension. Instead there is always a zero row wi record inserted with 'Unspecified' in all the columns. When the fact table is populated in the ETL, if the fact record doesn't have a corresponding dimension record the WID is poulated with zero.
    This removes the problems with outer joins and helps considerably with performance.
    This could be one practice you take from BI Apps and put into your own ETL's and data model.
    Regards
    Robin

Maybe you are looking for

  • How to get the last record??

    Hi, I now have to get only the last record from one table from MS Access. I was looking for the useful method from API, however, I cannot get it. How to get only the last record from one table ??? Please help, thanks.

  • Multitouch with Director

    Hi all, We are really intrigued to know whether Director is capable of authoring multi-touch shows - does anyone have any insight that they can offer? Happy to download plugins if needed, just need to know if it is possible.... Thanks!

  • Creative Cloud install is crashing WINdows 8 explorer.exe and then the application manager comes up blank?

    I download the Setup executable off of the site and run it, once Creative Cloud starts installing, my desktop and taskbar go black and don't respond, and then once the application manager is open, it attempts to load and then comes up blank - no menu

  • How to download a previous version of an object.

    Hi, one quick question: what is the easiest way to download a previous version of a source file in SCM? Say, for example, that I want to download v1.2 when the current (last) version is 1.4. Thanks in advance.

  • Windows Cardgames for Mac?

    Hi, Looking to switch my grandparents to Apple and guess what one of their favorite apps is? All those card games (freecell, solitaire, spider solitaire, hearts) that come with Windows. I was wondering if there were any recommendations (free preferra