Searching Criteria to find out the friends of friend

Senior DBA'S
i need to make database where i need to search the person from the current user. Current user can have many friends in his friend list but whom current user searching may be he is not a friend of current user and find out how current user known to that person. Like a friend's Chain.
Suppose that i m Aman finding out "San". my friends are Abhi, johan, satish etc,
further abhi's friend is "San" and
Satish is friend of Mohan, Mohan further friend of Sanju and Sanju will be friend of "San"
so "Aman" known to "San" by two ways one way by Abhi and 2nd way by Satish. Like link will be
Aman -> Abhi -> San
Aman -> Satish -> Mohan -> Sanju -> San
which way i am asking that is used by linkedin (www.linkedin.com)
So, Please tell me what best searching criteria will be used to achieve the target with performance because Records can be in billions.

should be like that
create table PALS (
pal_id number primary key ,
Name varchar2(100));
drop table FRIENDS;
create table FRIENDS(
pal_id number ,
friend_id number ,
primary key(pal_id , friend_id),
foreign key (pal_id) references PALS(pal_id),
foreign key (friend_id) references PALS(pal_id)
insert into pals values (1,'A');
insert into pals values (2,'B');
insert into pals values (3,'C');
insert into pals values (4,'D');
insert into pals values (5,'E');
insert into pals values (6,'F');
insert into pals values (7,'G');
insert into friends values (1,2);
insert into friends values (1,3);
insert into friends values (2,5);
insert into friends values (5,7);
insert into friends values (3,4);
insert into friends values (4,6);
insert into friends values (6,7);
commit;
-- find leads to G
with PF as (
select p.pal_id, p.name, f.friend_id, pf.name friend
from pals p
join friends f on p.pal_id=f.pal_id
join pals pf on pf.pal_id=f.friend_id)
select level, pf.name, pf.friend
from PF
connect by prior pal_id = friend_id start with friend='G';
     LEVEL NAME       FRIEND  
         1 E          G         
         2 B          E         
         1 F          G         
         2 D          F         
         3 C          D          then you have to unwrap it in application.
May be it is possible in SQL also.
Edited by: Mark Malakanov (user11181920) on Jan 10, 2013 10:56 AM
I've found how to do it
with PF as (
select p.pal_id, p.name, f.friend_id, pf.name friend
from pals p
join friends f on p.pal_id=f.pal_id
join pals pf on pf.pal_id=f.friend_id),
W as (
select level, pf.name, pf.friend,
CONNECT_BY_ROOT name R,
SYS_CONNECT_BY_PATH(friend,' -> ') P,
CONNECT_BY_ISLEAF IsLeaf
from PF
connect by pal_id = prior friend_id start with name='A'
select R || P P from W where IsLeaf=1 and friend='G';
P                                                                             
A -> B -> E -> G                                                                
A -> C -> D -> F -> G  Edited by: Mark Malakanov (user11181920) on Jan 10, 2013 11:28 AM
Edited by: Mark Malakanov (user11181920) on Jan 10, 2013 11:33 AM
So, Please tell me what best searching criteria will be used to achieve the target with performance because Records can be in billions.create index PALS_NAME on PALS(NAME);
or use PAL_ID in
connect by pal_id = prior friend_id start with PAL_ID=1
Edited by: Mark Malakanov (user11181920) on Jan 10, 2013 11:42 AM
Edited by: Mark Malakanov (user11181920) on Jan 10, 2013 11:44 AM

Similar Messages

  • How to use statement "search" to find out the asterisk in a string?

    Hi Guys,
       I encouter this question:I need to use "search" statement to find out the asterisk or the underscore in one string,you know these two symbols are wildcards. I don't know how to use statement "search" to find them??
       could you please give me some help!!
    Thanks a lot,Villy.Lv
    Edited by: Villy Lv on Sep 26, 2010 6:50 AM

    Hi,
    You cant usesearch statement, rather did you try with CS using IF condition? even you can go with loop statement too.
    DATA STRING TYPE STRING.
    DATA C TYPE C.
    DATA LEN TYPE I VALUE 0.
    DATA I TYPE I VALUE 0.
    LEN = STRLEN(STRING).
    LOOP LEN > I
         C = STRING+I.
         IF(C == '*' OR C == '_').
         ENDIF.
         I = I + 1.
    ENDLOOP.
    This way also you can use.
    Hope this may help you.
    Regards!
    Sheik

  • How to search this value in oracle database to find out the table

    Hi expert,
    I know there is a value in oracle database, please show me how to search this value in oracle database to find out the table holding this value.
    Many Thanks,

    918440 wrote:
    Hi friends,
    this question is really practical, I already know there is value from application saved in database, I want to search the whole database to figure out which table the value is contained.write SQL that writes SQL to query every table.
    Handle:     918440
    Status Level:     Newbie
    Registered:     Mar 2, 2012
    Total Posts:     20
    Total Questions:     10 (10 unresolved)
    why do you waste time here when you NEVER get any answer to any question you post?

  • How to find out the amount assigned to WBS element

    Hello Friends,
    Will you please inform how to find out the (amount/value/budget) assigned
    to WBS element
    Which Table it is stored in?
    Thanks in Advance
    Bset Regards
    Diwakar

    Hi Diwakarnd,
    You can use any of the following reports to get the information you require.
    1. <b>S_ALR_87013557</b> - Budget/Actual/Variance
    2. <b>S_ALR_87013558</b> - Budget/Actual/Commitment/Rem Plan/Assigned
    3. <b>S_ALR_87013559</b> - Budget/Distributed/Plan/Distributed
    Some of these reports use a complex selection criteria from various tables which has been grouped together, logically by SAP. The Logical Database table name for PS is <b>PSJ</b>.
    Execute transaction code <b>SE36</b> -> <b>PSJ</b> -> (Subobject : Radio button <b>Structure)</b> -> Click on <b>Display</b>.
    You would see all the underlining tables used.
    I hope the above helps.
    Do not forget to award the points please.
    Regards,
    Jacob

  • How to find out the list of patches applied without using inventory?

    Hi,
    I have been asked this question once.
    How will you find out the list of patches applied to Oracle Database Home without using commands like opatch lsinventory -detal etc...
    I think registry$history is a view from where we can find out the list of patches applied.
    But I think it will not include all the bug fixes,stand alone or one-off patches.It will mainly list out the CPU patches applied(correct me if I am wrong).
    Thanks,
    Rushi

    Hi;
    Thanks Helios,
    Your welcome
    Could you tell me how do you all senior people manage to find metalink note for almost everything?There is nothing special, For me I just make more search at metalink than googling so after sometimes you started to notice which note could be related wiht issues more clearly.. Just keep searching at metalink and focus what you are searching only.. ;)
    If you could guide me I can do it my self and stop bothering you for some silly doubts.You dont bother me and also I belive the other forum users ;) We are also learning new information wiht user questions ;)
    Regard
    Helios

  • How to find out the list of implemented OSS Notes in a particular period.

    Hi Friends,
    Need help.
    I need to find out the list of OSS Notes implemented in a period in a particular system.
    Could you please suggest the table or program or any way to find out the OSS Notes Implemented date wise?
    Thanks in Advance.
    Sreenivas

    Hi Sreenivas.
    How did you find the solution to this? Trying to do the same thing!
    Cheers,
    Tom

  • How to find out the list of includes:

    Hi,
    I want to find out the list of includes, hw can I do that..
    Suppose: ex: I want to know all the includes starting with zabc* hw can I do it, and one more question, where all the (total) includes will be stored.
    Akshitha.

    Hi akshitha,
    1. We can do that from se38.
    2. in se38, Press Ctrl + F
    3. A new window will come for search.
    4. <b>by pressing 4th button on toolbar, expand the search window.</b>
    5. <b>In "Program Type", enter   :   I   (for include only)
       In Program Name" enter    : ZABC*</b>
    6. Execute.
    regards,
    amit m.

  • How to find out the user-exits?

    hi.
    how to find out the user-exits?
    regards
    eswar.

    Hi,
    *& Report  ZEXITFINDER
    *report  zexitfinder.
    *& Enter the transaction code that you want to search through in order
    *& to find which Standard SAP User Exits exists.
    *& Tables
    tables : tstc, "SAP Transaction Codes
    tadir, "Directory of Repository Objects
    modsapt, "SAP Enhancements - Short Texts
    modact, "Modifications
    trdir, "System table TRDIR
    tfdir, "Function Module
    enlfdir, "Additional Attributes for Function Modules
    tstct. "Transaction Code Texts
    *& Variables
    data : jtab like tadir occurs 0 with header line.
    data : field1(30).
    data : v_devclass like tadir-devclass.
    *& Selection Screen Parameters
    selection-screen begin of block a01 with frame title text-001.
    selection-screen skip.
    parameters : p_tcode like tstc-tcode obligatory.
    selection-screen skip.
    selection-screen end of block a01.
    *& Start of main program
    start-of-selection.
    Validate Transaction Code
    select single * from tstc
    where tcode eq p_tcode.
    Find Repository Objects for transaction code
    if sy-subrc eq 0.
    select single * from tadir
    where pgmid = 'R3TR'
    and object = 'PROG'
    and obj_name = tstc-pgmna.
    move : tadir-devclass to v_devclass.
    if sy-subrc ne 0.
    select single * from trdir
    where name = tstc-pgmna.
    if trdir-subc eq 'F'.
    select single * from tfdir
    where pname = tstc-pgmna.
    select single * from enlfdir
    where funcname = tfdir-funcname.
    select single * from tadir
    where pgmid = 'R3TR'
    and object = 'FUGR'
    and obj_name = enlfdir-area.
    move : tadir-devclass to v_devclass.
    endif.
    endif.
    Find SAP Modifactions
    select * from tadir
    into table jtab
    where pgmid = 'R3TR'
    and object = 'SMOD'
    and devclass = v_devclass.
    select single * from tstct
    where sprsl eq sy-langu
    and tcode eq p_tcode.
    format color col_positive intensified off.
    write:/(19) 'Transaction Code - ',
    20(20) p_tcode,
    45(50) tstct-ttext.
    skip.
    if not jtab[] is initial.
    write:/(95) sy-uline.
    format color col_heading intensified on.
    write:/1 sy-vline,
    2 'Exit Name',
    21 sy-vline ,
    22 'Description',
    95 sy-vline.
    write:/(95) sy-uline.
    loop at jtab.
    select single * from modsapt
    where sprsl = sy-langu and
    name = jtab-obj_name.
    format color col_normal intensified off.
    write:/1 sy-vline,
    2 jtab-obj_name hotspot on,
    21 sy-vline ,
    22 modsapt-modtext,
    95 sy-vline.
    endloop.
    write:/(95) sy-uline.
    describe table jtab.
    skip.
    format color col_total intensified on.
    write:/ 'No of Exits:' , sy-tfill.
    else.
    format color col_negative intensified on.
    write:/(95) 'No User Exit exists'.
    endif.
    else.
    format color col_negative intensified on.
    write:/(95) 'Transaction Code Does Not Exist'.
    endif.
    Take the user to SMOD for the Exit that was selected.
    at line-selection.
    get cursor field field1.
    check field1(4) eq 'JTAB'.
    set parameter id 'MON' field sy-lisel+1(10).
    call transaction 'SMOD' and skip first screen.
    Regards

  • How to find out the list of all user's whose passwords are expired

    Hi
    i had tried to find out the list of all user's whose passwords are expired.
    i had written some jndi code by finding the max age and then find out the current time and subtracted this current time from max age using the following code
    "Attributes attbts=ctx.getAttributes("cn=pwdpolicy");
    String maxAge=(String)attbts.get("pwdMaxAge").get();
    Date Today = new Date();
    System.out.println("maxAge"+maxAge);
    long curTime=(Today.getTime())-Long.parseLong(maxAge)*1000;"
    and then parse it and create a string time as follows
    String time=year+month+day+hour+minute+second+"Z";
    where "year" "month" etc were parsed from curTime
    now i can get the list by using following code
    "String filterCriteria="(&(objectclass=person)(pwdChangedTime>="+time+")";
    NamingEnumeration results = ctx.search(baseDN,filterCriteria, sc); "
    but the current time which i am getting is the time of my system not the time of ldap server
    so my questions are following;
    1.Can there is any way by which i can get the tivole sever's system time.
    2.If there is no way then can you suggest any other way to find out the list of user's whose passwords are expired.
    please help me.
    Thanks.
    Krishan Rathi.

    Hi,
    Thanx for ur reply..
    I got the list from the table...
    thanks,
    sivagami

  • How to find out the user list that created by someone?

    Hi all:
    Now I want to develop a program that can find out the user list created by someone.
    such as :
    John create 3 user in SAP ,they are u1,u2,u3.
    Susan create 2 user in SAP , they are s1,s2.
    I input the the parameter such as John , the program can give me the list :u1,u2,u3.
    Could you tell me which table should I use in this program?
    Thanks .
    Elisa.

    Hi Ling,
    As per my understanding, you are looking for listing down the number of Users created by a particular users of the System. Like a System Administrator has created some 30 users. If this is correct, then you can use the table
    USR02 - Logon Data (Kernel-Side Use). This table has 2 fields which are of importance - BNAME - User Name in User Master Record & ANAME - Creator of the User Master Record. You can query the ANAME with the username of the system and you will get the resultant users.
    But I would reccomend to search the Table for a standard class, function module or RFC or BAPI so that you can reuse the same and need not to develop from the scratch.
    Hope this will help.
    Thanks,
    Samantak.

  • How can I find out the angle of a straight line between two anchor points?

    I would like to extend a line which is at a given angle (not 45,90 degree). Is there a quick and reliable way to do this? or to find out the angle of a segment?
    What I'm doing at the moment is just direct selecting an anchor point and using the visual guides to extend it. I don't think this is exact though so was I wondering if anyone had any techniques for doing this?
    Thanks!

    portfelio,
    Smart Guides are your friends.
    As a general solution, you may:
    1) With the Line Segment Tool ClickDrag between the two Anchor Points (Smart Guides say anchor);
    2) With the appropriate Reference Point selected in the Transform palette, increase the W or H value and Ctrl/Cmd+Enter;
    3) Lock the new auxiliary line;
    4) ClickDrag the relevant Anchor Point of the original line along the extended auxiliary line (Smart Guides say path);
    5) Unlock and delete the auxiliary line.
    After 1), you may also click the Line Segment Tool to see the angle.
    Or,  in a case with a straight path (segment), you may use the Scale Tool:
    1) (Direct) Select the straight path (segment);
    2) Switch to the Scale Tool and Click the Anchor Point that is to stay, then ClickDrag the one to move (Smart Guides say uniform when you are dragging in the right direction).

  • How to find out the metachian from subchain

    hello friends,
    could you please let me know , how to find out the meta chain from subchian .
    I know the subchain name and wanted to check that this chian is included in which meta chian ,
    actaully here so many chain , so its confusing .
    Is there any way ?

    Hi,
    Pls chk this links,
    Re: Meta chains - how to create n example scenerios
    Re: How to create process chains, infopackage groups & Meta chains
    Hope this helps,
    regards
    CSM reddy

  • How to find out the file name

    Hi,
    In selection screen (parameter) user will give input TXT file from presentation server to upload to SAP. I need to capture the file name only but not the path and need to concatenate with date stamp and need to download error log in XLS file to presentation server.
    How to find out the file name from selection screen?
    I searched SCN threads but not found relavant solution.
    Thanks,
    R Kumar

    Hi
    This code gets only filename from selection screen :
    REPORT x.
    PARAMETERS p_file(100).
    DATA : gv_full_path LIKE  ibipparms-path,
           gv_full_path_string TYPE string,
           gv_filename(100),
           gv_file_ext(3).
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
    Ask user to select file with a popup :
      CALL FUNCTION 'F4_FILENAME'
        IMPORTING
          file_name = gv_full_path.
    Get filename from path :
      gv_full_path_string = gv_full_path.
      CALL FUNCTION 'CH_SPLIT_FILENAME'
        EXPORTING
          complete_filename = gv_full_path_string
        IMPORTING
          extension         = gv_file_ext
          name              = gv_filename.
      CONCATENATE gv_filename '.' gv_file_ext INTO gv_filename.
      p_file = gv_filename.
    I hope it helps.

  • How to find out the idoc type required for our requirement

    Hi,
         How to find out the list of available idoc type in SAP. It will be good if i get to know the table name where all the idoc type definitions are gets stored.
    Say i have some requirement and for that requirement how i can find the proper idoc type to be used. (assume functional consultant is not providing that information)
    Points will be given for the useful answers
    Thanks,
    Prasanna

    Hi prasanna,
                    we can get SAP idoc types in tcode we31.For every requirment there will be different message type.
    For example we want idoc type for account invoice receipt.
    First find out message type for that purpose which can be found in we81-ACC_INVOICE_RECEIPT.
    Get this message type and search in we82  where we can find message type and idoc type linkage.
    try this way.
    Reward if it is usful.
    Thanks,
    Srikanth.A

  • How to Find out the all  tables in module wise ?

    Dear Friends,
    1.How to Find out the all  tables in module wise ?
       what are the total number of table in SAP ?
    2. how to find out all existing functions in SAP ?
    Thanks and regards,
    Subasha Chandra Sahoo.

    Hi,
    You will get the module wise list from:
    http://www.sourceveda.com/SAPReference.htm
    http://www.sourceveda.com/
    Regards...

Maybe you are looking for

  • ITunes 12.1.1.4 and iOS 8.2 Unable to Sort Videos!

    I'm using a Windows 7 64-bit OS. I just upgraded iTunes to version 12.1.1.4, as well as my iPad 2 to iOS version 8.2. As a result of these upgrades, I now find that the TV shows downloaded to my iPad are no longer sorted according to the name of the

  • Parent Child Hierarchy  (N Level Hierarchy ) in BI 4.0

    Hi , We have following table structure . We are trying to create parent-child hierarchy and  implement drill on the same . We are using Oracle  database as RDBMS. e.g. Child Key    Parent Key 1    2                 1 3                 1 4            

  • XML document re-construction

    Hello, I am trying to create pc of code that will recover an XML document that has some parsing error within. Today we are catching the exception and marking the XML doc as bad one, however, it would be nice to know what child node caused the problem

  • Web fonts are not displaying

    Hello - For some reason my Firefox install is not displaying web fonts properly - It may have been doing this before the 13 upgrade. Doesn't matter if it's @font-face or Typekit or whatever, it's just goes down the fallback list until it finds one th

  • Shuts down when connected to itunes

    I was given an iPod and I think there's something fishy about it.  First of all, it looks like an iPod Classic.  It says 80GB on the back metal casing (the front is white), but in the setting it says it has 159GB available, but the capacity id s 903M