How to get multiple row data in single row for one value of foreign key

i want to get data from a table in a way that all the emp_id corresponding to one manager_id
in employee table come in one row. (emp_id is the primary key and manager_id is the foreign key) Since there are different emp_id whose manager_id is same
so how can i get all the emp_id in one row .

One way with 10g:
select mgr,
       rtrim(xmlagg(xmlelement(empno,empno||',').extract('//text()')),',')  emps
from emp
where mgr is not null
group by mgr;10g:
-- define this function:
create or replace
function concatenate(c Sys_refcursor, sep varchar2 default null) return varchar2
as
  val varchar2(100);
  return_value varchar2(4000);
begin
--  open c;
  loop
  fetch c into val;
  exit when c%notfound;
  if return_value is null then
    return_value:=val;
  else
    return_value:=return_value||sep||val;
  end if;
  end loop;
  return return_value;
end;
select mgr,
       concatenate(cursor(select empno from emp e where e.mgr=emp.mgr order by empno),',')
from emp
where mgr is not null
group by mgr;With 11g:
select mgr,
       listagg(empno,',') within group (order by empno) emps
from emp
where mgr is not null
group by mgr;

Similar Messages

  • I loos my APPLE ID, I have a new one, how can get access to data stored in the old one?

    I loos my APPLE ID, Now I have a new one, how can get access to data stored in the old one?

    Do you have the email & password of the old Apple ID?

  • Converting multi-row data to single row

    My source table has one or more records with the same id. My destination table only has one record for each id. I wish to combine the records from my source table to my destination table. I think the following query will show what I'm trying to do:
    update TARGET_TABLE
    set (A)
    =
    (select (case
    when sum(A*FUEL_TYPE_ID) > 2 then 4
    else sum(A*FUEL_TYPE_ID)
    end)
    from SOURCE_TABLE
    group by additive_id)
    where additive_id = NEW_TABLE.additive_idSince I'm currently limited to Apex SQL Commands, the error information is minimalist:
    ORA-01427: single-row subquery returns more than one row
    How should I be doing this?

    Hi tharpa,
    Are u able to relate to this.
    create table emp2 as select * from emp;
      update emp2
      set sal=(
                  select sum(sal)
                   from emp
                   group by deptno)
    where   empno=7839
    -------correct one would be-------
       update emp2 e2
       set sal=(
                 select sum(sal)
                  from emp e1
                  where e1.deptno=e2.deptno
                  group by deptno)
        where   empno=7839
         Hope it helps
    CKLP
    Edited by: CKLP on Apr 11, 2011 5:17 AM

  • Q. How to get multiple results from a single column in a recordset using PHP

    Hi everyone
    Hope someone can help. I have a column called categories and about 5 categories listed. I want to show all products that are listed in say 2 categories. I only have basic php skills so only know how to pass a url value to show the products from 1 category e.g. 
    Select *
    FROM product
    WHERE category = colname
    $colname = $_GET['category'];
    URL...page.php?category=fruit
    Questions is how do I get the products from multiple categories to show e.g. all products from categories 'fruit', 'dairy', 'meat'
    Your help will be much appreciated as I am getting tired of beating my head against the wall. (should invent a PHP wall pillow and sell it online)
    Thanks

    $colname1 = $_GET['category1'];
    $colname2 = $_GET['category2'];
    $colname3 = $_GET['category3'];
    Select *
    FROM product
    WHERE category IN  ('$colname1', '$colname2', '$colname3')
    >Your help will be much appreciated as I am getting tired of beating my head against the wall
    My guess is that you are trying to build a web application without having first learned the basics on PHP and SQL. That's certainly the hard way.

  • How to apply multiple actions on a single file in one go to generate multiple watermarked pdfs?

    usually i need to create many watermarked datasheets for different customers using a single base pdf. currently i run individual actions for individual customers on the same file which means i have to runs 10s of individual actions every time i have  new source file. can i make a single action or a script which will take a single source file, run multiple actions(~15-20) for watermarks and save these files separately? basically what i need is instead of running many individual actions i run a single action/script to make it automatic. if yes, how to do so?

    Hi Monte,
    You can achieve this by assigning a secondary extension to another button, but this might not be what you want, so if you can elaborate a little further as to what you want exactly I can help you with putting together a solution
    Cheers,
    David Trad.
    **When you rate a persons post, you are indicating a thank you or that it helped, but at the same time you are also helping to maintain the community spirit - You don't have to rate posts and you wont be looked down upon :) **

  • How to get Multiple FLV duration?

    How to get Multiple FLV duration in single shot?.  Am using Netstream concept.

    I have more flv files and taking it via XML. I want to play the multiple flv video in single timeline. For that i need duration of multiple flv in for loop. Is it possible to take without metadata?

  • Data services and one to many foreign keys?

    Hi,
    I am playing with the data features in Flash4.  I can get a flex app to work that will query and update a J2EE entity that has no foreign keys, but when I try the same with an entity that has many to one foreign keys I get a null pointer error coming from the server.  I created a servlet to do the same update and that worked.
    I'm wondering if the issue is a casting issue.  I know I have to do the configure data types thing to some of the generated service calls to let it know what action script class is appropriate (instead of a generic object ) e.g. findAll().  Do I have to do a similar thing for one to many foreign key situations?  i.e. lets say i have a department - employees model.  On the java side the department entity has a variable that is a set of employees.  In the department.as class I'd have a employees field thats an ArrayCollection.  Do I have to let it know somewhere that this is an ArrayCollection of employee.as objects?
    FYI, I've already changed to eager fetching of the fk values.
    Does anyone have this working?
    Thanks,
    Bill

    Hi,
    Thanks for your feedback!
    This looks like an issue.
    Can you please log a bug in http://bugs.adobe.com/flex with your sample.
    Thanks,
    Balaji
    http://balajisridhar.wordpress.com

  • How to get multiple records using fn-bea:execute-sql()

    Hi,
    I created Proxy service(ALSB3.0) to get records from DB table. I have used Xquery function(fn-bea:execute-sql()). Using simple SQL query I got single record, but my table having multiple records. Please suggest how to get multiple records using fn-bea:execute-sql() and how to assign them in ALSB variable.
    Regards,
    Nagaraju
    Edited by: user10373980 on Sep 29, 2008 6:11 AM

    Hi,
    Am facing the same issue stated above that I couldnt get all the records in the table that am querying in the Proxyservice.
    For example:
    fn-bea:execute-sql('EsbDataSource', 'student', 'select Name from StudentList' ) is the query that am using to fetch the records from the table called StudentList which contains more than one records like
    Id Name
    01 XXX
    02 YYY
    03 ZZZ
    I tried to assign the result of the above query in a variable and while trying to log the variable, I can see the below
    <student>
    <Name>XXX</Name>
    </student>
    I want to have all the records from my table in xml format but it's not coming up. I get the value only from the first row of my table.
    Please suggest.
    regards,
    Venkat

  • How to get multiple measures in measure hierarchy in Essbase Studio

    Hi All,
    Previously we are using one measure column which will gives the count.Now the current requirement is to get multiple measures in measure hierarchy.
    For Example
    Measure
    Count
    SalesCount(count*Sales/10)
    CustomerCount(count*customer/10)
    In the fact we will be having only column called "count".
    So,I created the remaining two user defined dimension elements and applied formula in filters.
    When i am using individual dimension element in measure hierarchy the data is coming correct,However when I am combing these three hierarchies under measure hierarchiy I am getting no data.Can someone help me out how to resolve this issue
    Thanks,
    SatyaB

    Thanks Gleen.
    This is how the actual scenerio,currently i am creating a cube for testing domain.
    For all defects we will having a column called defect count.Now there are asking a new requirement to add addtional metrics contains sev1open defect,sev2 open defect etc...
    So,I created hierarchy like this
    Measures(Hierarchy)
    Count
    SalesMeasure
    For this member I returned in filter as ( 'contains'( connection : 'STATUS', "New" ) and 'contains'( 'TESTING_SEVERITY', "2-High" ))
    However when I am trying build this individually working fine getting correct data
    When I am combining due to overwrite it seems getting no data.Like this I have to create 16 metrics
    Is there any other method where I can proceed further to resolve this issue
    So,can you help me on this Gleen.Thanks
    Regards,
    SatyaB

  • Multiple rows in a single row.

    I want to know how can I store the values of multiple rowe in a single row.for an example..
    machine name    manchine no  frequency   month
    Lathe                  MOO1          yearly         jan
    Lathe                  MOO1          halfyearly   feb
    Lathe                  MOO1         weekly       march and so on
    I want this in a single row..
    like                        jan       feb             march
    Lathe       M001   yearly     halfyearly   weekly.
    and in a single row I want this as per the month specified .
    In my report I have 12 months distribution for each machine.

    Taruna,
    Just make sure understand the scenario correctly. Would you like to store the row in DB like this:
    Lathe MOO1 yearly jan,feb,mar
    then you expect to show in the report like this:
    Lathe MOO1 yearly jan
    Lathe MOO1 yearly feb
    Lathe MOO1 yearly mar
    Yes, you can do it this way, but somehow break the 1st principle of DB schema design - Atomic
    Of course, you need to convert jan,feb,mar into list and display for each row.
    string monthStr = "jan,feb,mar";
    string [] months = monthStr.Split(",");
    Kind Regards
    -Yatsea

  • How to handle multiple tables data in Entity Beans?

    How to handle multiple tables data in Entity Beans?
    i mean, my bean (non trivial) is responsible for frequent
    insertion in one table and some deletion on another table.
    Can anyone of you...please..?

    Is your data model right? If you are adding in one and deleting in another it sounds to me more like a process that an entity, in which case you may revisit your data model and simplify it, add in a session bean with the process method to co-ordinate between the two.
    However, if you want to map multiple different tables within a single entity bean it is possible and just part of the mapping. How you actualyl specify it depends on which implementation you are working with.
    Cheers,
    Peter.

  • How to get length of data on column with long datatype

    How to get length of data on column with long datatype without using pl/sql block

    ...another reason not to use LONG datatype for columns.
    Oracle advises to switch to LOB columns instead
    SQL> create table t
      2  (x long)
      3  /
    Table created.
    SQL> insert into t values (rpad ('x', 10000, 'x'))
      2  /
    1 row created.
    SQL> alter table t
      2  modify x clob
      3  /
    Table altered.
    SQL> desc t
    Name                                      Null?    Type
    X                                                  CLOB

  • Get multiple selection data of Table into an internal table

    Hi Guys,
    I have a Table in my view layout and selected 'SelectionMode' as 'Multi' in the table properties.How to get the selected data into an internal table when rows selected on the table output.For example,I have a 10 rows in the table and selected only 5 rows,need to get these 5 rows into an internal table?
    Regards
    Nandana

    Hi,
    Here is some sample code. Please try this and let me know if you are still getting any errors.
    DATA lo_nd_table_node TYPE REF TO if_wd_context_node.
      DATA lo_el_table_node TYPE REF TO if_wd_context_element.
      DATA ls_table_node TYPE wd_this->element_table_node.
      DATA lt_table_node TYPE wd_this->elements_table_node.
      DATA lt_table TYPE wdr_context_element_set.
      lo_nd_table_node = wd_context->get_child_node( name = wd_this->wdctx_table_node ).
      lt_table = lo_nd_table_node->get_selected_elements( including_lead_selection = abap_true ).
      LOOP AT lt_table INTO lo_el_table_node.
        lo_el_table_node->get_static_attributes(
          IMPORTING
            static_attributes = ls_table_node ).
        APPEND ls_table_node TO lt_table_node.
        CLEAR ls_table_node.
      ENDLOOP.
    lt_table_node contains the selected rows.

  • Data in single row

    thanks
    Edited by: 786304 on May 25, 2011 12:22 PM

    BluShadow .
    I agree your opinion.
    I resurrect it from google cache.
    Hi All,
    I have two queries as follows
    Select
    Xrc.Profile_Nbr Var_Profile_Nbr,
    xsr.Profile_Nbr Var_Profile_Nbr,
    Nvl(Ppa.First_Name,' ') Var_First_Name,
    Nvl(Ppa.Last_Name,' ') Var_Last_Nmae,
    Nvl(Ppa.Last_Name2,' ') Var_Last_Name2,
    Nvl(Ppa.Middle_Name,' ') Var_Middle_Name,
    Nvl(Pfl.Display_Name,' ') Var_Display_Name,
    Nvl(Addr.Street1,' ') Var_Street1,
    Nvl(Addr.Street2,' ') Var_Street2,
    Nvl(Addr.City,' ') Var_City ,
    Nvl(Addr.State_Name,' ') Var_State_Name,
    Addr.Post_Code Var_Post_Code,
    Nvl(Cnt.Cntry_Name,' ') Var_Country,
    Phn.Phone Var_Phone_Nbr,
    Nvl(To_Char(Ppa.Birthdate,'MON/DD/YYYY'),' ') Var_Birthdate,
    Nvl(Ppa.Occupation,' ') Var_Occupation,
    Nvl(Ppa.Country_Of_Nationality,1) Var_Country_Of_Nationality,
    Nvl(Ppa2.First_Name,' ') Var_First_Name,
    Nvl(Ppa2.Last_Name,' ') Var_Last_Nmae,
    Nvl(Ppa2.Last_Name2,' ') Var_Last_Name2,
    Nvl(Ppa2.Middle_Name,' ') Var_Middle_Name,
    Nvl(Pfl2.Display_Name,' ') Var_Display_Name,
    Nvl(Addr2.Street1,' ') Var_Street1,
    Nvl(Addr2.Street2,' ') Var_Street2,
    Nvl(Addr2.City,' ') Var_City ,
    Nvl(Addr2.State_Name,' ') Var_State_Name,
    Addr2.Post_Code Var_Post_Code,
    Nvl(Cnt2.Cntry_Name,' ') Var_Country,
    Phn2.Phone Var_Phone_Nbr,
    Nvl(To_Char(Ppa2.Birthdate,'MON/DD/YYYY'),' ') Var_Birthdate,
    Nvl(Ppa2.Occupation,' ') Var_Occupation,
    Nvl(ppa2.COUNTRY_OF_NATIONALITY,1) var_COUNTRY_OF_NATIONALITY
    From
    V_Xact_Receiver Xrc, V_Person_Profile Ppa, V_Profile Pfl,V_Phone Phn,V_Address Addr,V_Country_Lu Cnt
    ,V_Xact_sender xsr, V_Person_Profile Ppa2, V_Profile Pfl2,V_Phone Phn2,V_Address Addr2,V_Country_Lu Cnt2
    Where Xrc.Xact_Hdr_Nbr=71138142
    and xsr.Xact_Hdr_Nbr=71138142
    And xrc.Profile_Nbr=Ppa.Profile_Nbr
    And Ppa.Profile_Nbr=Pfl.Profile_Nbr
    And Pfl.Profile_Nbr=Phn.Profile_Nbr
    And Pfl.Profile_Nbr=Addr.Profile_Nbr
    And Phn.Country_Nbr=Cnt.Country_Nbr
    And Xsr.Profile_Nbr=Ppa2.Profile_Nbr
    And Ppa2.Profile_Nbr=Pfl2.Profile_Nbr
    And Pfl2.Profile_Nbr=Phn2.Profile_Nbr
    And Pfl2.Profile_Nbr=Addr2.Profile_Nbr
    And Phn2.Country_Nbr=Cnt2.Country_Nbr;
    and
    SELECT
    Nvl(Dlu.Id_Type_Desc,' ') Var_Ident_Type_Desc,
    Nvl(D.Id_Number,' ') Var_Id_Number,
    Nvl(To_Char(D.Id_Issue_Date,'MON/DD/YYYY'),' ') Dte_Id_Issue,
    Nvl(To_Char(D.Id_Expiration_Date,'MON/DD/YYYY'),' ') Dte_Id_Expiration,
    Nvl(To_Char(Id_Expiration_Date,'MON/DD/YYYY'),' ') Dte_Id_Expiration,
    Nvl(D.Id_Issue_Place,' ') Var_Issue_Loc,
    Nvl(Pfl.Occupation,' ') Var_Occupation,
    Nvl(To_Char(Pfl.Birthdate,'MON/DD/YYYY'),' ') Dte_Birth,
    Nvl(To_Char(Pfl.Country_Of_Nationality,'MON/DD/YYYY'),' ') Var_Country_Of_Nationality
    FROM V_PROFILE_IDENT D,
    V_ID_TYPE_LU DLU,
    V_Country_Lu Clu,
    V_Xact_sender Xsr,
    v_person_profile pfl
    Where Xsr.Xact_Hdr_Nbr='71138142'
    And D.Profile_Nbr = Xsr.Profile_Nbr
    and D.Profile_Nbr=pfl.Profile_Nbr
    And D.Id_Type_Nbr = Dlu.Id_Type_Nbr
    And D.Country_Nbr = Clu.Country_Nbr(+)
    And D.Is_Valid = 'Y'
    and rownum<=3;
    The first query it returns the result in a single row
    The second query it returns the output in 3 rows
    while i was club these two it gives the result in 3 rows
    but have to get the result in a single row with all appropriate values side by side if the values are same get the values one only
    and the query club as
    Select
    Xrc.Profile_Nbr Var_Profile_Nbr,
    xsr.Profile_Nbr Var_Profile_Nbr,
    Nvl(Ppa.First_Name,' ') Var_First_Name,
    Nvl(Ppa.Last_Name,' ') Var_Last_Nmae,
    Nvl(Ppa.Last_Name2,' ') Var_Last_Name2,
    Nvl(Ppa.Middle_Name,' ') Var_Middle_Name,
    Nvl(Pfl.Display_Name,' ') Var_Display_Name,
    Nvl(Addr.Street1,' ') Var_Street1,
    Nvl(Addr.Street2,' ') Var_Street2,
    Nvl(Addr.City,' ') Var_City ,
    Nvl(Addr.State_Name,' ') Var_State_Name,
    Addr.Post_Code Var_Post_Code,
    Nvl(Cnt.Cntry_Name,' ') Var_Country,
    Phn.Phone Var_Phone_Nbr,
    Nvl(To_Char(Ppa.Birthdate,'MON/DD/YYYY'),' ') Var_Birthdate,
    Nvl(Ppa.Occupation,' ') Var_Occupation,
    Nvl(Ppa.Country_Of_Nationality,1) Var_Country_Of_Nationality,
    Nvl(Ppa2.First_Name,' ') Var_First_Name,
    Nvl(Ppa2.Last_Name,' ') Var_Last_Nmae,
    Nvl(Ppa2.Last_Name2,' ') Var_Last_Name2,
    Nvl(Ppa2.Middle_Name,' ') Var_Middle_Name,
    Nvl(Pfl2.Display_Name,' ') Var_Display_Name,
    Nvl(Addr2.Street1,' ') Var_Street1,
    Nvl(Addr2.Street2,' ') Var_Street2,
    Nvl(Addr2.City,' ') Var_City ,
    Nvl(Addr2.State_Name,' ') Var_State_Name,
    Addr2.Post_Code Var_Post_Code,
    Nvl(Cnt2.Cntry_Name,' ') Var_Country,
    Phn2.Phone Var_Phone_Nbr,
    Nvl(To_Char(Ppa2.Birthdate,'MON/DD/YYYY'),' ') Var_Birthdate,
    Nvl(Ppa2.Occupation,' ') Var_Occupation,
    Nvl(Ppa2.Country_Of_Nationality,1) Var_Country_Of_Nationality,
    Nvl(Dlu.Id_Type_Desc,' ') Var_Ident_Type_Desc,
    Nvl(D.Id_Number,' ') Var_Id_Number,
    Nvl(To_Char(D.Id_Issue_Date,'MON/DD/YYYY'),' ') Dte_Id_Issue,
    Nvl(To_Char(D.Id_Expiration_Date,'MON/DD/YYYY'),' ') Dte_Id_Expiration,
    Nvl(To_Char(Id_Expiration_Date,'MON/DD/YYYY'),' ') Dte_Id_Expiration,
    Nvl(D.Id_Issue_Place,' ') Var_Issue_Loc,
    Nvl(Pfl3.Occupation,' ') Var_Occupation,
    Nvl(To_Char(Pfl3.Birthdate,'MON/DD/YYYY'),' ') Dte_Birth,
    Nvl(To_Char(Pfl3.Country_Of_Nationality,'MON/DD/YYYY'),' ') Var_Country_Of_Nationality
    From
    V_Xact_Receiver Xrc, V_Person_Profile Ppa, V_Profile Pfl,V_Phone Phn,V_Address Addr,V_Country_Lu Cnt
    ,V_Xact_sender xsr, V_Person_Profile Ppa2, V_Profile Pfl2,V_Phone Phn2,V_Address Addr2,V_Country_Lu Cnt2
    V_Profile_Ident D,
    V_Id_Type_Lu Dlu,
    V_Country_Lu Clu,
    V_Xact_receiver Xrc2,
    v_person_profile pfl3
    Where Xrc.Xact_Hdr_Nbr=71138142
    And Xsr.Xact_Hdr_Nbr=71138142
    and xrc2.Xact_Hdr_Nbr=71138142
    And xrc.Profile_Nbr=Ppa.Profile_Nbr
    And Ppa.Profile_Nbr=Pfl.Profile_Nbr
    And Pfl.Profile_Nbr=Phn.Profile_Nbr
    And Pfl.Profile_Nbr=Addr.Profile_Nbr
    And Phn.Country_Nbr=Cnt.Country_Nbr
    And Xsr.Profile_Nbr=Ppa2.Profile_Nbr
    And Ppa2.Profile_Nbr=Pfl2.Profile_Nbr
    And Pfl2.Profile_Nbr=Phn2.Profile_Nbr
    And Pfl2.Profile_Nbr=Addr2.Profile_Nbr
    And Phn2.Country_Nbr=Cnt2.Country_Nbr
    And D.Profile_Nbr = Xrc2.Profile_Nbr
    and D.Profile_Nbr=pfl3.Profile_Nbr
    And D.Id_Type_Nbr = Dlu.Id_Type_Nbr
    And D.Country_Nbr = Clu.Country_Nbr(+)
    And D.Is_Valid = 'Y'
    and rownum<=3;
    regards,

  • How to get multiple selected fields in list

    Hello all,
    I am trying to get multiple selected value from a list but i dont know how to get multiple selected fields from a list though AS3.
    Actually i want to pass the selected fields to php, so for that i need to get the selections and send to php.
    Thankx..

    i want to put the selected fields of list in an array through AS3....
    actually......i figured it out how to do that...........
    Its simple......use
    list.selectedItems[index]
    and to get the number of items selected......
    list.selectedItems.length
    simple.....

Maybe you are looking for

  • Error while creating a Material

    Hai Friends,           I am facing a problem while creating,display,change material. i.e i am unable to create a new material or edit/display an existing material.          The error is : Record ZP doesnot exist in table T113E.          Message No: M

  • How to find out which cube/ods has the code

    hi, I want to find out which cube/ods has the start routine/update rules written in it.  Is there a table or Tcode to find out the code instead of opening each cube/ods to find out whether there is code in it or not. Thanks, Sam

  • How do change my icon from i photo back to color

    how do i change my icon from iphoto back to color

  • Terminal doesn't take password

    My friend's Leopard-equipped PowerBook G4 latch is broken, so I'm trying to turn off automatic lid wake on that laptop, as I have done successfully on my own PowerBook G4 with Tiger. I can paste or type the usual command into Terminal... sudo pmset l

  • Viewing the contents of jar files

    If I have 5 jar files and I want to search for a specific package on these jar files what command does jar have to search for this? I need to search for a package called org/apache/XML in 5 jar files Is this possible or do I need to extract the files