Linking two tables in SQL

Hi,
Iam struggling with SQL for this scenario..can you please through some light on this.
Table A:
Order Number || W.O.Number || Enetrprise || ResourcePool
1 || 1 || A || RP1
2 || 2 || A || RP1
3 || 3 || A || RP2
4 || 4 || A || RP2
5 || 5 || A || RP3
B
ResourcePool || Available Date
RP1 || 20-Dec-2007
RP1 || 21-Dec-2007
RP1 || 22-Dec-2007
RP2 || 20-Dec-2007
RP2 || 21-Dec-2007
RP3 || 20-Dec-2007
RP3 || 21-Dec-2007
My query should fetch
Order Number|| W.O.Number|| Enetrprise|| ResourcePool|| Available Date
1 || 1 || A || RP1 || 20-Dec-2007
1 || 1 || A || RP1 || 21-Dec-2007
1 || 1 || A || RP1 || 22-Dec-2007
2 || 2 || A || RP1 || 20-Dec-2007
2 || 2 || A || RP1 || 21-Dec-2007
2 || 2 || A || RP1 || 22-Dec-2007
3 || 3 || A || RP2 || 20-Dec-2007
3 || 3 || A || RP2 || 21-Dec-2007
4 || 4 || A || RP2 || 20-Dec-2007
4 || 4 || A || RP2 || 21-Dec-2007
5 || 5 || A || RP2 || 20-Dec-2007
5 || 5 || A || RP2 || 21-Dec-2007
when Iam including A.resourcepool=B.resourcepool in the query its returning no rows.
Thanks

(repeated)
select Order Number,W.O.Number, Enetrprise, a.ResourcePool, Available Date
from a,b
where a.resourcepool=b.resourcepool;
this is the simplest join condition.
just check whether you have some data in those tables!

Similar Messages

  • In ER DIagram using toad( how can i link two tables)

    Hi,
    Any Toad expert can guide me that how can i link two tables in Toad in ER Diagram to show the relationship between two tables.
    Thanks

    Hi,
    I hope there is foreign key relationship in tables, if so then you can click on "Find table dependencies" icon which will draw lines between them.
    ~Vinod

  • Query for Linking Two Tables without Reference

    Hi Folks,
    Good Day!
    I have this dilemma on how to link two tables without a reference. In the Business Partner Master Data, there is a field for the Territory which is from the table OTER. This OTER focuses on its description. Once you have added the particular Territory for that Business Partner, it is being stored in the Territory field of the BP right? Our client wants to have an automated way of searching for the Business Partner's Profit Center in creating a Sales Order wherein it is the same as the Business Partner's Territory. The Profit Center is from the table OPRC.
    When I create a Sales Order, after I have entered the Business Partner/Customer Code, the Profit Center should have the value of the Profit Center Code wherein it is the Business Partner's Territory. My query will go like this:
    Enter the BP/Customer Code automatically the Profit Center code where Profit Name = BP's Territory.
    OTER and OCRD don't have connections. How can it be?
    I'm thinking of retrieving the Territory first before the Profit Center but can you suggest of any other way?
    Thank you much!
    Regards,
    Fringe

    Hi Fringe,
    Okay, I already understood your case here. I presume your configuration as follows:
    OTER (Territory)
    territryID - descript
    1 - Philippine
    2 - Indonesia
    3 - Germany
    OPRC (Cost Centre)
    PrcCode - PrcName
    25 - Philippine
    33 - Indonesia
    47 - Germany
    Was above illustration correct? Then, you could use this formatted search in Cost Centre / Dimension field in Sales Order rows
    SELECT PrcCode FROM OPRC WHERE PrcName=(
    SELECT TOP 1 descript FROM OTER T0
    INNER JOIN OCRD T1 ON T0.territryID=T1.Territory
    WHERE T1.CardCode=$[OCRD.CardCode.0])
    However, I suggest you use a little bit different approach here. Since you can't define Territory Code / Territory ID (you could only type the Territory name, Philippine etc.), why don't you standardize Territory name with Cost Centre code? Let say, you define Philippine as PHI, Indonesia as INA, Germany as DEU and so on. Therefore, user can read the Cost Centre or more precisely Distribution Rules in Sales Order form in more familiar way.
    OTER (Territory)
    territryID - descript
    1 - PHI
    2 - INA
    3 - DEU
    OPRC (Cost Centre)
    PrcCode - PrcName
    PHI - Philippine
    INA - Indonesia
    DEU - Germany
    When FMS worked in Sales Order document, your user will read PHI instead of 25, should be more familiar to them. With that being said, you could use simpler FMS
    SELECT descript FROM OTER T0
    INNER JOIN OCRD T1 ON T0.territryID=T1.Territory
    WHERE T1.CardCode=$[OCRD.CardCode.0]
    You only need to maintain consistency between Territory Name and Cost Centre code. Just my two cents. Hope this help.
    Best Regards,
    Hendry Wijaya

  • How to link two tables?

    Hello,
    I'm trying to create invoices with Pages, but my question is how can I link two tables in one Pages document?
    Or having two Header Rows with some 'normal' rows between would also be great. (even better)
    I'm trying to calculate my subtotal etc. below my overview of articles.
    Thanks in advance!
    Andy

    (1) no way to link two tables in Pages.
    (2) you may have several header rows, several footer rows but you can't have standard rows between header (or footer) ones.
    You may achieve what you describe without the asked feature.
    Use correct ranges and you will be able to calculate subtotals.
    Yvan KOENIG (VALLAURIS, France) lundi 28 décembre 2009 19:02:38

  • Linking two table..it is look like unpivot but it is not

    Hi guys, I got a situation like this:
    Table A
    create table #fly (company varchar (50), period varchar(6), adcost (int), ppcost (int))
    insert into #fly values ('PanAm', '201401', 100, 200) ,  ('PanAm', '201402', 200, 200) , ('PanAm', '201403', 700, 1000), ('EGAm', '201401', 1100, 1200), ('EGAm', '201402', 7100, 7200)                                                                                                                 
    Table 2 #Cost (firm varchar (100), client varchar (100), period varchar(6), element (varchar 10), tot int) insert into #firm ('Zuck', ''Panam', '201401', ''adcost', 40), ('Zuck', ''Eagam', '201401', ''adcost', 40), ('Zuck', ''Panam', '201402', ''ppcost', 240)                
    As you can see I got in fly the field adcost that is a value in the table #cost. I need to link the two table and I'm wondering whitch is the best way. Another issue is the adcost (#fly) has in #cost two relatives adcost and fixadcost element. I should consider
    both the elements as adcost.  Advices? Thanks

    create table #fly (company varchar (50), period varchar(6), adcost int, ppcost int)
    insert into #fly values ('PanAm', '201401', 100, 200) , ('PanAm', '201402', 200, 200) , ('PanAm', '201403', 700, 1000), ('EGAm', '201401', 1100, 1200), ('EGAm', '201402', 7100, 7200)
    create table #Cost (firm varchar (100), client varchar (100), period varchar(6), element varchar (20), tot int)
    insert into #cost values ('Zuck', 'Panam', '201401', 'adcost', 40), ('Zuck', 'Eagam', '201401', 'adcost', 40)
    , ('Zuck', 'Panam', '201401', 'fixedadcost', 40)
    , ('Ford', 'Panam', '201401','ppcost', 240)
    select * from #Cost
    select * from #Fly
    Select company,f.period,adcost, (c1.tot+c2.tot) as [adcost + fixedadcost] , ppcost, c3.tot as [ppcost from Cost] from (select company,period,adcost,ppcost from #Fly
    WHERE company='PanAM' AND period='201401') f
    left join #Cost c1 on c1.period = f.period AND c1.client=f.company AND c1.element ='adcost'
    left join #Cost c2 on c2.period = f.period AND c2.client=f.company AND c2.element ='fixedadcost'
    left join #Cost c3 on c2.period = f.period AND c3.client=f.company AND c3.element ='ppcost'
    drop table #Cost, #Fly

  • Linking two tables with no duplicated records!

    Hi,
    I have two tables now with both tables is having the common filed matnr.
    now using this field MATNR from  first table ,i need to fetch projectno from the other table which has to be unique.if there are more than one entry found for MATNR in question then that must not be updated to the first table!
    any ideas?
    Raj

    hi raj,
    try this code.
    data:
      ld_count type p,
      ld_tabix type sy-tabix.
    loop at itab1.
      move sy-tabix to ld_tabix.
      ld_count = 0.
      loop at itab2 where matnr eq itab1-matnr.
        add 1 to ld_count.
      endloop.
      if ld_count = 1.
        read table itab2 with key matnr = itab1-matnr.
        move itab2-project to itab1-project.
        modify itab1 index ld_tabix.
      endif.
    endloop.

  • To link two tables in ap

    hi
    could someone pls guide me to link ap_invoices_all table with gl_code_combinationsthanking in advance
    Edited by: makdutakdu on Oct 14, 2010 12:15 PM

    Hello.
    Use the following query (R11i):
    SELECT i.invoice_num "Invoice Nr.",
    c.segment1 "Segment1",
    l.ae_line_type_code "Line Type",
    l.accounted_dr "Debit",
    l.accounted_cr "Credit"
    FROM ap_ae_lines_all l, ap_ae_headers_all h, ap_invoices_all i, ap_accounting_events_all e, gl_code_combinations c
    WHERE e.source_table = 'AP_INVOICES'
    AND i.invoice_num = '<your invoice nymber>'
    AND l.ae_header_id = h.ae_header_id
    AND e.accounting_event_id = h.accounting_event_id
    AND e.source_id = i.invoice_id
    AND l.code_combination_id = c.code_combination_id
    AND i.org_id = <your org_id>
    As you may have more than one invoice with the same number, the query may return more lines then expected. To restrict it, enter the vendor_id from table AP_INVOICES_ALL.
    Hope this helps.
    Octavio
    Edited by: Octopus Rex on Oct 14, 2010 4:10 AM

  • Linking 2 tables with Sql Expressions or add command

    Hi
    I want to make a custom table using a union all using cr2008 but I'm unable to find/enable the sql expressios field? It's just not there?
    I've tried using the add command is the database expert but I cant see how to get this work.. I have 2 data sources that each consist of identical tables (but different data).  I have 2 tables I want to link:
    datasource1 statstable
    datasource2 statstable
    So I want to do:
    SELECT * FROM datasource1 statstable
    UNION ALL
    SELECT * FROM datasource2 statstable
    but it wont let me do this as the 2 stats tables are in different datasouces.
    I would really appreciate any help you can give me.
    thanks

    you can not do this unless you use busines views.
    you can not create one report based on two different datasources using crystal reports,
    my advice to you to solve this problem
    start to look for the "business views"
    which allow you to create a strucutre based on many different datasources, you create 2 connections for your datasources and map them in the view.
    then you use those business views in crysal reports to create you report.
    it may looks complicated, but i admit its too easy and not hard.
    you can get a small book about business views manager which comes with BO XI R2 or Xi 3.0
    from the business objects support site.
    i hope it was clear for you
    good luck

  • Linking two table views

    Dear all,
    I am creating an iView within VC which runs two BI queries from one variant input form.
    From the outputs i can create two output tables which supply all the information i require.
    My question is, can I combine the results of the two outputs and select from both outputs the information i want to display and deliver it in one output table. I will have one common key within both sets of data.
    Unfortunately the BI reports can not be changed due to their setup
    Regards
    PS.

    Hello,
    It may be related with the configuration of the model (how input and output ports are connected).
    Please have a look at below thread. It is quite in detail:
    [How to use the Union operator;
    -arda.

  • Query that link two tables together

    I am using this query to extract  Account Payable data:
    SELECT T0.DocNum, T0.DocStatus, T0.DocDate, T0.DocDueDate, T0.CardCode, T0.CardName, T0.NumAtCard, T0.DocTotal FROM Akron.dbo.OPCH T0
    How would I also add the unique number for each individual payment from these tables?
    OVPM and VPM2.
    What field links these 2 tables together?

    Hi,
    You may check this: Incoming Payments Report
    Replace all INV with PCH and RCV with VPM
    Thanks,
    Gordon

  • Combine two tables T-SQL

    Hi there,
    It might be simple Query for you but I was missing the logic.
    I have Tab A    this does have 4 records.
               Tab B  this does have 14 records.
    Note: those 4 records exists in Tab B
    I want to insert rest of the 10 records into the Tab A.
    Any suggestion pls.
    Thanks,
    Siva 

    Hi,
    Please run the below script and see if it serves your requirement.
    DECLARE @TableA TABLE
    ID INT,
    NAME VARCHAR(10)
    INSERT INTO @TableA 
    VALUES   (1, 'James')
    ,(2, 'Ramz')
    ,(3, 'Chandu')
    ,(4, 'Suraj')
    SELECT *
    FROM @TableA
    DECLARE @TableB TABLE
    ID INT,
    NAME VARCHAR(10)
    INSERT INTO @TableB 
    VALUES   (1, 'James')
    ,(2, 'Ramz')
    ,(3, 'Chandu')
    ,(4, 'Suraj')
    ,(5, 'Krishna')
    ,(6, 'John')
    SELECT *
    FROM @TableB
    Now as per your requirement, you need to insert rows 5 & 6 from TableB into TableA
    INSERT INTO @TableA
    SELECT Tab1.* 
    FROM @TableB Tab1
    LEFT JOIN @TableA Tab2 ON Tab1.id = Tab2.id
    WHERE Tab2.id IS NULL
    The above query gives inserts the non-existing records 
    SELECT *
    FROM @TableA
    Thanks, Satish Chandra

  • Join two table using two link field

    hi all
    i need to left join two table, and to link two table need to match two field
    ex: the link field is store_name and id
    i use below sql statement
    SELECT A1.store_name, A1.id, A1.card, A2.sale, A2.history
    FROM Georgraphy A1, Store_Information A2
    WHERE A1.store_name = A2.store_name(+)
    AND A1.id = A2.id(+)
    but it's wrong
    please tell me how to left join A1 and A2, thx!

    Whats your aim?
    Any error message?
    SQL> select * from geography;
            ID STORE_NAME
             1 a
             1 b
             2 a
             2 b
    SQL> select * from store_information;
            ID STORE_NAME
             1 a
             3 d
    SQL> SELECT *
      2  FROM Geography A1, Store_Information A2
      3  WHERE A1.store_name = A2.store_name(+)
      4  AND A1.id = A2.id(+);
            ID STORE_NAME         ID STORE_NAME
             1 a                   1 a
             2 a
             2 b
             1 b                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to specify more than Two Tables in NATURAL JOIN

    Hi,
    I am using Oracle9i R-2. I want help in writing a Query using Two Tables in SQL*PLUS. I am using ANSI/ISO Standrard for table-joins:
    select col1, col2, descr
    from tab1 natural join tab2
    There are two columns col1 & col2 is common between thse two tables. So, it will join them and query execute well.
    How can i use 3rd table tab3 in the same way in Natural Join...? If column col1 & col2 is available in tab3 also.
    I tried this way, but it gives me error:
    select col1, col2
    from tab1 natural join tab2 natural join tab3
    Is it possible to specify more than two tables in Natural Join Clause.
    Please check that out & help please. Thanks.
    Regards,
    Kamesh Rastogi

    I do not get an error when I try the same thing on the same version, as demonstrated below. Can you post your table structure and a copy and paste of a run of your actual query with the error that you are receiving?
    scott@ORA92> select banner from v$version
      2  /
    BANNER
    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
    PL/SQL Release 9.2.0.1.0 - Production
    CORE     9.2.0.1.0     Production
    TNS for 32-bit Windows: Version 9.2.0.1.0 - Production
    NLSRTL Version 9.2.0.1.0 - Production
    scott@ORA92> select * from tab1
      2  /
          COL1       COL2 COL3
             1          1 A
            10         10 B
    scott@ORA92> select * from tab2
      2  /
          COL1       COL2 COL4
             1          1 C
            20         20 D
    scott@ORA92> select * from tab3
      2  /
          COL1       COL2 COL5
             1          1 E
            30         30 F
    scott@ORA92> select col1, col2, col3, col4, col5
      2  from tab1 natural join tab2 natural join tab3
      3  /
          COL1       COL2 COL3 COL4 COL5
             1          1 A    C    E
    scott@ORA92>

  • How to link two databased

    I have to link two tables from two differen databases.
    select vendor from table a database e
    select vendor from table b database c
    how can i combine this two tables

    You create a database link. Assuming you are on database e:
    CREATE DATABASE LINK c_link
      CONNECT TO name_of_c_database_user_with_select_privilege_to_table_b
      IDENTIFIED BY password_of_c_database_user_with_select_privilege_to_table_b
      USING 'c_database_tns_entry_name'
    /Keep in mind 'c_database_tns_entry_name' must exists in tnsnames.ora on database e server.
    Now you can:
    select vendor from table_a
    union all
    select vendor from table_b@c_link
    /SY.

  • How link between the two tables

    Hi All
    In fact, I am new in Oracle and also, in this forum, and I hope that I find useful and benefited also reportedly.
    My oracle is Oracle Database 10g Express Edition.
    I have now two tables and one for staff and the second of the equipment used by staff.
    Well now how link between tables in the agenda third.
    Thanks

    You could read one of the many books on the subject, or you could just try something real simple like
    SQL> desc a
    Name                    Null?    Type
    USERNAME                NOT NULL VARCHAR2(30)
    PROFILE                 NOT NULL VARCHAR2(30)
    SQL> desc b
    Name                    Null?    Type
    USERNAME                         VARCHAR2(30)
    ROLENAME                NOT NULL VARCHAR2(30)
    SQL> select * from a natural join b;
    USERNAME         PROFILE      ROLENAME
    USER_ONE         DEFAULT      CRISYS_SYSADMIN
    USER_TWO         END_USER     USER_CONNECT
    USER_TWO         END_USER     CARS_APP_USER
    USER_THREE       BATCH_USER   BATCH_CONNECT
    USER_THREE       BATCH_USER   APPLICATION_OWNER
    etc.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Maybe you are looking for

  • Getting pictures off of a broken iphone

    on my olf iphone 4 the screen is broken, making it not able to use, i need my pictures off of it, i tried using icloud but i did not put my pictures on icloud, and i have a passcode on m old phone, so i cannot back up my iphone to itunes, how can i g

  • `MS Office for Mac 2004

    I'm a recent convert from WIN98 so I still have a lot to learn. I'm using 10.4.11 Tiger on an Alum iMac with Parallels and MS XP. I use MS Word 2002 on the XP side and NeoOffice on the OS X side. I am watching on eBay several offerings of the subject

  • Please Help me in Labview and MS Access Database Connective

    Please Help me in LabVIEW and MS Access Database Connective through an example . I am new to LabVIEW .I need simple example that take a data from a table and display it on front panel . thanks in advance .

  • Need help in generating L4 Traffic monitor logs

    Hi, As a part of my project I need to study different types of logs produced by Cisco IronPort. I could generate some access and authentication logs however not sure about generating the L4 Traffic Monitor logs. Can anyone point me to right documenta

  • Help! Reinstalled itunes but it says i need incompatible need 64bit

    HELP! I just uninstalled itunes and reinstalled it and now whenever i hook up an ipad or iphone it says 'This iphone cannot be used because the required software is not installed. Run the itunes installer to remove itunes, then install the 64-bit ver