To Identify Relationship between records in a table

Hi
I need to write a query to identify what relationship exists between records in a table.
For example,In our system a manager can have more than 1 subordinate as well as an employee can also have more than 1 manager.
I need to provide the relationship for a given set of employee-ids whether it is
1 is to 1,
1 is to many,
many is to 1,
many to many.
Employee     Relationship     Relationship Description
John     1 is to M     Implies John is reporting to multiple managers who have only one subordinate
Stuart     1 is to 1     Implies Stuart is reporting to only one manager who has only one subordinate
Robert     M is to 1     Implies Robert is reporting to only one manager who has multiple subordinates
Martha     M is to M     Implies Martha is reporting to multiple managers who have multiple subordinates
Can you please help me with this query?
Regards
Kapil

To make things simple lets assume the following table structure and data
CREATE TABLE EMP
ENAME VARCHAR2(10),
MNAME VARCHAR2(10)
Data for M:1 Relationship
INSERT INTO EMP VALUES ('John','Linda');
INSERT INTO EMP VALUES ('Robert','Linda');
Data for 1:M Relationship
INSERT INTO EMP VALUES ('Peter','Stuart');
INSERT INTO EMP VALUES ('Peter','Linda');
Data for 1:1 Relationship
INSERT INTO EMP VALUES ('Mary','Tim');
Data for M:M Relationship
INSERT INTO EMP VALUES ('Chris','Roger');
INSERT INTO EMP VALUES ('Tom','Roger');
INSERT INTO EMP VALUES ('Stephen','Roger');
INSERT INTO EMP VALUES ('Stephen','Zoe');
Now if I search for Chris and Mary I should get the result as:-
Chris M:M
Mary 1:1
Hope this clarifies ;-)

Similar Messages

  • How to create a Foreign key relationship between 2 user defined tables...

    Hi Folks,
    I have created two user defined tables... Where in i want to create foriegn key relationship between the 2 tables.... Can anyone guide the step by step procedure to do this scenario...
    Any help would be highly appreciated...
    Thanks

    Hi
    1.  In the 2nd table call the field of the 1st table which is a primary key.
    2.  Give the same field and dataelement name.
    3.  Select that field and then click on the foreign key field icon which is beside Search Help button.
    4. Then give short text, and the 1st table name.
    5. Then in the below box give the 2nd table name and 2nd table field name which you have called from 1st table.
    6. Then click on copy, then u will be able to see Check table name and check table field name beside foreign key table name.
    7. Then again click on copy.
    Regards
    Haritha.

  • Relationship Between PO / GR / Services Tables

    Hello experts
    I am trying to find out the relationship between ESSR ESLH ESLL EKPO and EKBE tables.
    Below is some sample data and my requirement. Could you please tell me how I should consider linking the tables. Am I missing any table in between. Out of the 2 sevices , only one is accepted , 300000003. I need information like PO#, SES#, Sevice#, Accepted Qty, Mat. Document#
    EKPO                              
    EBELN     EBELP     PACKNO                    
    4300000000     10     289271                    
    ESLH                              
    PACKNO     FPACKNO     HPACKNO     EBELN     EBELP          
    289271     289271     289271     4300000000     10          
    289272     289271     289271     4300000000     10          
    ESLL                              
    PACKNO     INTROW     EXTROW     SRVPO        PACKAGE        SUB-PACKNO     ACT_WERT
    289271     1     0                    X        289272            0
    289272     2     10     3000000003                0            10
    289272     3     20     3000000002                0             0
    ESSR                              
    LBLNI        PACKNO     EBELN     EBELP               
    1000052342     289279     4300000000     10               
    EKBE                              
    EBELN         EBELP     VGABE     BELNR          BEWTP     LFBNR     
    4300000000     10     9     1000052342     D     1000052342     
    4300000000     10     1     50000451255     E     1000052342     
    WHAT I NEED                               
    EBELN          EBELP     LBLNI          SRVPO     ACT_WERT     BELNR     
    4300000000     10     1000052342     3000000003     10     50000451255     
    Many thanks & regards!
    Sanjyot

    Hi Experts
    I'm haveing a similar problem, and I need your help.
    I'm trying to connect PO number with Service entry sheet and service numbers, but the link between tables don't work.
    EXEMPLE:
    EKPO
    EBELN    PACKNO
    1010          212
    ESSR
    EBELN   LBLNI       PACKNO
    1010        2000         215
    Link between PO and Service entry sheet - DONE (NOT using ESSR-PACKNO)
    ESLH
    EBELN    KNUMV     HPACKNO     FPACKNO     PACKNO
    1010          10               212               209               212
    1010          11               212               212               213
    ESLL
    PLN_PACKNO SRVPOS
    213                        1
    213                        2
    So, going to ESLH and getting the PACKNO, will allow me to go do ESLL and get the SRVPOS.
    The problem is that for a certain PO I have, in ESLH 2 entries.
    Can anyone confirm that EKPO-PACKNO=ESLH-FPACKNO and not HPACKNO? I think that would solve my problem.
    If someonehas other ideas, please let me know.
    Many thanks,
    Joana Faria

  • One to One relationship between Dimensions and Fact Tables

    Hi,
    Not a real Discoverer question, but seeing as there is such a huge pool of talent here, I thought I'd ask anyway...
    Is the concept of having a one to one join between a Dimension and a Fact Table an Acceptable Thing (tm). I'm not talking about a degenerate dimension, as the Dimension would hold additional attributes.
    It's something I'm trying to get my head around and would appreciate any viewpoints.
    Thanks,
    Andy

    Hi Andy,
    There is of course no distinction in SQL between 1-1 and 1-n joins, but in your database design you would avoid denormalizing data into a dimension table if it was only ever used once.
    From a Discoverer perspective setting the join to 1-1 controls how aggregate queries are constructed. Normally, if you have a master-detail 1-n relationship and you aggregate items in both tables then you will get an incorrect result for the master table because the number of rows are multipled by the n detail records. Similarily if you have 2 detail tables in the query and you aggregate items in a detail table you will get incorrect results. Discoverer recognises these situations and raises an error.
    Setting the join as 1-1 tells Discoverer that it will get the correct results in these situations and therefore no error is raised. So it is perfectly acceptable to set the joins as 1-1 as long as you know the implications.
    Hope that helps,
    Rod West

  • How to implement one to many relationship between two Document Line Table

    Hi,
    I want to implement the following relationship into user defined tables:
    Example Situation:
    There are tables A, B and C.
    For one record of Table A, there could be multiple records in table B.
    For one record of Table B, there could be multiple records in table C.
    i.e. A(1) -> B(n) [One to many relationship]
         B(1) -> C(n) [One to many relationship]
    finally: A(1) -> B(n) -> C(n)
    How can I achieve this? If I make Table A as Document and table B & C as Document Line and then make them UDO, will it work? Kindly suggest me a solution.
    Regards,
    Sudeshna.

    Hi,
    I think that the database representation is exactly what you ask for. 3 tables, A, B, C. A should have a UDF that is linked to B table, and B should have a UDF that is linked to C table.
    You should manage the database transactions, and the UI to support all this stuff.
    Regards,
    IBai Peñ

  • One to one relationship between records while entering in MDM data manager?

    Example Scenario::
         I have created <b>Employee details</b>(main table) and<b> Salary</b> (look up flat table for employee number filed in main table) .  Tried to get the corresponding employee's gross salary from <b>salary</b> table to <b>employee Details</b> table basing on <b>Employee number</b> field in Employee Details table as <b>Gross salary</b> and <b>Employee number</b> are common fields for both the tables. But i could not get one to one relationship in this case , Please explain how to achieve?

    Employee Details (Main Table)
                   EmpNo(Look up field)      EmpNa     GrossSal(Look up field)
    Salary Details  (Look Flat Table)
         Empno         Basic Sal        GrossSal   
          012              5000             10000
                     013              4000               8000
    I have created two tables with the above fields. In main table i kept two look up fields to Salary Details table. First i have entered data to salary table as above , now when i am trying to enter data in to main table EmpNo as 012 it should show Gross salary as 10000 automatically as per the corresponding EmpNo. Instead it is showing all the Grosssal values of Salary table.

  • Is there a Report to Identify Relationships Between Projects

    Hi,
    We currently have a problem where people have been copying and pasting activities from other older projects into our current project. In doing this they have also copied over the logic. So the pasted activites are still linked to the older project.
    Is it possible to run a report to show the Project ID's which will allow us to identify which activities are pointing to the wrong project.
    Thanks

    Karl,
    You can create an excel spreadsheet which lists the Activity Relationships along with the Project ID. Go to File > Export > Spreadsheet > Activity Relationships. You should be able to select Predecessor Project and/or Successor Project in the Columns section of the Template. Once you run the export, you should be able to generate a spreadsheet which has the results you need.
    An alternative would be to create a Report using the Reports Wizard. In the Reports Wizard template, choose Activity Relationships, and then you should be able to choose Predecessor Project as a column in the Columns section of the Template.
    Either of these methods should provide the results you are looking for.
    Hope this helps!

  • Relationship between PRPS and FPLT table

    How to arrive to a billing plan in FPLT table with project ID or WBS ID in PRPS table.
    Thanks,
    Vaishnavi

    Hi
    I hope there is no common element in both tables..extract the mile stone data from FPLT and MLST tables and then WBS element data from PRPS and MLST tables (first two gives the mile stone and next two tables gives the WBS element to which mile stone is attached)..
    thanks

  • Relationship between mara and mast table

    Hi gurus i have to get the components of one material for example
    if the material is paper i need to know the components of this paper (cellulose)
    any idea?
    i know all materials are in mara table but i find the transaction  cs03 i put a trace and i can see that this transaction uses de mast table but i dont know how to relate the mast table with mara table

    Pass the material and plant to function module CSAP_MAT_BOM_READ, this fm is used in CS03.
    Note: This will will only give you the immediate level, so again pass the material obtained from fm to the same fm to get the next level.
    Is you requirement to only get the child components of a FERT part ?

  • RELATIONSHIP BETWEEN VBAK/VBAP AND V46R_HEAD TABLE

    Hi,
    can you please tell me that is there any relationship between VBAK and  V46R_HEAD TABLE or VBAP and V46R_HEAD TABLE table.
    where V46R_HEAD TABLE is a structure and i want to display sme fields of vbak and some of V46R_HEAD  and some of VBAP.
    I got the relation between VBAK and VBAP ie. the field VBELN. But i am not getting the relation with V46R_HEAD sturcture.
    Please help me to solve this problem.

    Hi,
    the field vbeln is present in V46R_HEAD also.
    Please check it!!  Please do a CTR+F and look for VBELN.
    Regards.

  • Multiple relationships between 2 tables in report model

    if i have 2 relationships between the same two tables. how do i use one over the other?
    for example, i have 2 tables order and ordeDate table , with the definition of:
    order table:
    orderid int,
    qty int,
    orderdate date)
    and orderDate table:
    (id int,
    endOfDay date,
    endOfMonth date)
    i created one relation ship as orderDate = endOfDay and anothe relationship as orderDate = endOfMonth. some of my reports would need to use the relationship between orderDate = endOfDay and the month end reports would need to use yhe relationship between
    orderDate = endOfMonth. How do I select one relationship over the other when building the report?
    Ideally the database should have been redesigned, which cannot be done at the moment as this will be done on the next project

    Your table design is completly wrong. I am now sure how you are maintaining OrderDate table. SQL Server is RDBMS. Without relation how will you pick those rows from Order table whose order date is equal exactly equal to datefield in OrderDate table. The
    only way is to derived endofDay and endofMonth in the select query directly. I understand endofMonth. But what is EndofDay ? And that too a date datatype ??
    You can run the below query but it will not return specific order date from order table,
    SELECT * FROM [ORDER] WHERE
    CONVERT(CHAR(10),ORDERDATE,101) IN (SELECT CONVERT(CHAR(10),endOfDay,101) FROM ORDERDATE)
    SELECT * FROM [ORDER] WHERE
    CONVERT(CHAR(10),ORDERDATE,101) IN (SELECT CONVERT(CHAR(10),endOfMonth,101) FROM ORDERDATE)
    Even if i JOIN the two table by orderdate and endofDay/endofMonth, we will not received specific orderDate. And this is becouse if your Order table contains multiple orderDate that are matching to either endofDay or endofMonth, the final output will contain
    multiple orderDate details. I don't think this is what you need. Therefore you need to modify the OrderDate table or provide us the definition for endofDay and endofMonth, and how are you maintaining.
    Regards, RSingh

  • How to find the table relationship between BSEG-BELNR with CE11000 table.

    Hi,
    Please help me to find out the table relationship between BSEG with CE11000 table.
    I have BSEG-BELNR value.
    Thanks in Advance
    Shankar

    Hello,
    BAsically the relationship can be foundon the basis of cost centre it will be good if you paste the structure ce11000.
    I have worked on it and as far i as i can recall it contain value fields right...like vv205,vv305 etc?
    Provide me more details.
    Are you preparing some reconcillation report for costing based COPA or Account based COPA..?
    Hopefully will help you out..
    Regards,
    Nabheet

  • Relationship between two facts

    I have 2 fact tables (Encounter and Visit) which have an optional 1 to many relationship.  For a query the users are trying to run, they are using DepartmentDim, which is related to both facts, and AppointmentStatusDim, which is related ONLY to VisitFact.
     They want to see a count of encounters by department and appointment status.  The problem is when they pull in the count from the Encounter measure group, it is showing the same count for all of the values in each row.  
    How do I need to create the relationship between the two fact tables so that I can use dimensions that are related to only one fact table but pull in a measure from the other fact?
    Any help is appreciated.
    Thanks,
    Andy

    Sounds like you need a bridge table to complete the M2M relationship...
    FactVisit
      DepartmentKey
      AppointmentStatusKey
      EncounterGroupKey
    FactEncounter
      DepartmentKey
      EncounterGroupKey
    BridgeVisitEncounter
      EncounterGroupKey
    DimAppointmentStatus <-- FactVisit --> BridgeVisitEncounter <-- FactEncounter 
    This will allow you to slice measures in the FactEncounter measure group by attributes in the DimAppointmentStatus dimension...
    BI Developer and lover of data (Blog |
    Twitter)

  • Identify duplicate records in a table

    I have this situation in the same table
    GOREMAL_PIDM     GOREMAL_EMAL_CODE     GOREMAL_EMAIL_ADDRESS     GOREMAL_STATUS_IND     GOREMAL_PREFERRED_IND
    2238954     REC1     [email protected]     A     Y
    2238954     REC1     [email protected]     A     N
    I need to identify those records (look they are the same(email address), just upper and lower case) then I need delete one the one with the GOREMAL_STATUS_IND = N
    I am running this query
    select
    a.goremal_pidm    pidm_a,
    b.goremal_pidm    pidmb,
    a.goremal_emal_code emal_codea,
    b.goremal_emal_code emal_codeb,
    a.goremal_email_address email_addressa,
    b.goremal_email_address email_addressb,
    a.goremal_status_ind    status_inda,
    b.goremal_status_ind    status_indb,
    a.goremal_preferred_ind preferred_inda,
    b.goremal_preferred_ind preferred_indb,
    a.goremal_activity_date activity_datea,
    b.goremal_activity_date activity_dateb,
    a.goremal_user_id        user_ida,
    b.goremal_user_id        user_idb,
    a.goremal_comment        commenta,
    b.goremal_comment        commentb,
    a.goremal_disp_web_ind   web_inda,
    b.goremal_disp_web_ind   web_indb,
    a.goremal_data_origin    origina,
    b.goremal_data_origin    originb
    FROM
    goremal a, goremal b, saradap
    WHERE
    --b.goremal_pidm = 2216086
    b.goremal_preferred_ind = 'N'
    AND a.goremal_preferred_ind = 'Y' 
    AND  a.goremal_emal_code = 'REC1'
    AND B.goremal_emal_code = 'REC1'
    and a.goremal_email_address =  b.goremal_email_address
    and a.goremal_pidm = b.goremal_pidm
    and a.goremal_pidm = saradap_pidm
    AND Saradap_term_code_entry = 200990
    AND Saradap_program_1 = 'UBA' to identify the records but it is not working sometimes give me recoirds that only have one row in the table (goremall)
    what will be a good way to do this, again I need to identify all the records that have 2 rows, but the email is the same then I need to delete the ones with the
    GOREMAL_STATUS_IND = N
    tHANK YOU

    Hi,
    user648177 wrote:
    Sorry but the previous answer won't work
    I need to be able to identify (before the delete) all the records
    like this one
    GOREMAL_PIDM     GOREMAL_EMAL_CODE     GOREMAL_EMAIL_ADDRESS     GOREMAL_STATUS_IND     GOREMAL_PREFERRED_IND
    2238954     REC1     [email protected]     A     Y
    2238954     REC1     [email protected]     A     N
    where the GOREMAL_EMAL_CODE are equal and the GOREMAL_EMAIL_ADDRESS is Y in one record and N in another record, then I will delete the records with N, but I want to de a select before I do the deleteWhat is wrong with Mathiasm's suggestion? What exactly "won't work" when you try it?
    It would help if you formatted the data so that the columns lined up and posted it between &#123;code&#125; tags.
    It could be that there was some confusion about what the column names were, and you only have to substitute the right names for it to work.
    If you want to see the rows that will be deleted, rather than actually deleting them, change "DELETE" to "SELECT *".

  • Query to find all relationships between tables

    Please help me wit the following
    Query to find all relationships between tables
    SAMPLE OUTPUT:
    PRIMTAB PRIMCOL FOREIGNTAB FOREIGN KEY
    DEPT DEPTNO EMP DEPTNO
    Return all records in the database.
    PLEASE HELP

    SET LINESIZE 150
    COLUMN primcol FORMAT A30
    COLUMN foreigncol FORMAT A30
    SELECT uc1.table_name AS primtab,
    ucc1.column_name AS primcol,
    uc2.table_name AS foreigntab,
    ucc2.column_name AS foreigncol
    FROM user_constraints uc1,
    user_constraints uc2,
    user_cons_columns ucc1,
    user_cons_columns ucc2
    WHERE uc1.constraint_name = uc2.r_constraint_name
    AND uc1.constraint_name = ucc1.constraint_name
    AND uc2.constraint_name = ucc2.constraint_name
    AND ucc1.position = ucc2.position
    ORDER BY uc1.table_name,
    ucc1.position
    /

Maybe you are looking for

  • How to clear Vendor Open item throgh the FBCJ T. Code

    Hello Dear All,                      I am doing a Cash Payment to the Vendor, through the FBCJ but at the time of making payment i want to clear the Vendor open item. it is possible in Cash Journal.                      And also I want to know that,

  • Confirmation of sensitive filed of customer master

    Hi all Is that possible to BLOCK or NOT TO CREATE a sales order, if confirmation of sensitive filed of customer master yet to confirm ? Is that need user exit or can we do Configuration. Need your suggestions. Regards, Nagesh

  • Using a Single Library for Entire Site and When to Use Subsites

    I'm hoping a discussion I am having with my coworkers can be solved.  We are trying to decide two things: Should the entire office be under a single site or should each division have their own site?  Our Office has 5 divisions that contain 17 Branche

  • HP Laserjet 3052 help

    I have searched this topic and have seen where some people have managed to get their printers back fully functional. My question is, how do you add the printer by ip address. It is clear that doing all the other steps involved disables the printer fu

  • How to create a single action listener for a group of buttons

    hi there.. i am new at java and i have a problem with my applet.. i am doing a virtual ticket programme.. i have a tab that says books seats.. in the tab, i am suppose to create 50 buttons. i have done that already by using for (int i=1; i<=10;i++) 5