Another SQL problem..help

Hi all,
There are two tables from which I want to select data.
one Person (columns: P_ID, name ...so on) and relationship(columns: P_ID, relationship_id
I want insert a P_ID and want the P_ID's of their related persons....
I am finding it difficult becuaes all the P_ID are in one table...
pls suggest the SQL statement...
Thanks

I have demonstrated two different methods below. The first query works in SQL or PL/SQL, however prior to 9i it requires dynamic SQL in order to execute in PL/SQL, due to the difference between the SQL and PL/SQL engines in older versions of Oracle. The second query only works with SQL*Plus, because BREAK is a SQL*Plus command.
SQL> -- test data:
SQL> SELECT * FROM person
  2  /
      P_ID NAME                                                                
      1233 peter                                                               
      1234 John                                                                
      1323 sam                                                                 
      1298 justin                                                              
      1278 Ken                                                                 
      1209 michael                                                             
      1897 george                                                              
      1898 amit                                                                
      1987 smith                                                               
      1989 bob                                                                 
      1698 denial                                                              
      1598 ash                                                                 
      1578 anthony                                                             
      1597 boby                                                                
14 rows selected.
SQL> SELECT * FROM relationship
  2  /
      P_ID RELATED_P_ID                                                        
      1323         1278                                                        
                   1209                                                        
                   1897                                                        
      1898         1987                                                        
                   1989                                                        
      1698         1598                                                        
                   1578                                                        
                   1597                                                        
8 rows selected.
SQL> --
SQL> --
SQL> -- query:
SQL> SELECT DECODE (rn, 1, p_id, NULL) AS p_id,
  2           DECODE (rn, 1, person, NULL) AS person,
  3           related_p_id, relative
  4  FROM   (SELECT a.p_id, b.name person, a.related_p_id, b2.name relative,
  5                ROW_NUMBER () OVER
  6                  (PARTITION BY a.p_id, b.name
  7                   ORDER BY     related_p_id) AS rn
  8            FROM   relationship a, person b, person b2
  9            WHERE  a.p_id = b.p_id
10            AND    a.related_p_id = b2.p_id
11            ORDER BY a.p_id, b.name)
12  /
      P_ID PERSON     RELATED_P_ID RELATIVE                                    
      1323 sam                1209 michael                                     
                              1278 Ken                                         
                              1897 george                                      
      1698 denial             1578 anthony                                     
                              1597 boby                                        
                              1598 ash                                         
      1898 amit               1987 smith                                       
                              1989 bob                                         
8 rows selected.
SQL> --
SQL> --
SQL> -- query:
SQL> BREAK ON p_id ON person
SQL> SELECT a.p_id, b.name person, a.related_p_id, b2.name relative
  2  FROM   relationship a, person b, person b2
  3  WHERE  a.p_id = b.p_id
  4  AND    a.related_p_id = b2.p_id
  5  ORDER BY a.p_id, b.name
  6  /
      P_ID PERSON     RELATED_P_ID RELATIVE                                    
      1323 sam                1209 michael                                     
                              1278 Ken                                         
                              1897 george                                      
      1698 denial             1578 anthony                                     
                              1597 boby                                        
                              1598 ash                                         
      1898 amit               1987 smith                                       
                              1989 bob                                         
8 rows selected.

Similar Messages

  • SQL problem - help needed ASAP!!

    Hey guys,
    Doing a college project... would really appreciate some help. I am trying to use a variable in the where clause of a select cursor in PL/SQL. The code is this:
    procedure results(p_search_entry varchar2, p_search_field varchar2) is
    cursor c_results is
    select * from physics_b where p_search_field = p_search_entry;
    begin
    for cv_results in c_results
    loop
    -- loop through actions
    end loop;
    The problem is that I don't know how to get the where clause to accept the variable passed into the procedure as the field name. Does anyone know the syntax for this?
    Thanks very much!
    Niall

    This isn't the correct forum for this kind of question. The SQL and PL/SQL forum PL/SQL is probably best.
    That said, you can't do what you want that way.
    You can do
    procedure results (p_search_entry in varchar2)
    cursor c_result is
    select * fro physics_b where subject=p_search_entry;(assuming subject is a column in physics_b)
    You can't use a variable to represent a column directly. You need to build the statement as a string and then use execute immediate.
    statement:='select * fro physics_b where '||p_search_field||' = :1';
    -- this bit is probably bad syntax.
    execute immediate statement using p_search_entry;Look up execute immediate and bind variables

  • Another N95 Problem Help!!!!

    Hi, i'm new to this forum, so hey all!
    Right down to business I've got an N95 an for some reason as of yesterday it's stopped alerting me as to when I have text messages i've redownloaded the device firmware and it's still having the same problem (v11 can't get v12 yet cos i'm on orange!)
    Has anyone got any ideas? any help would be much obliged
    KurpsMessage Edited by kurps on 07-Oct-200704:43 PM

    No they are not free.... Even though a window comes up saying that you have already purchased this App and ask if you want to download it again "free", you're billed again. At least I am.... I have had to restore from scratch (backups (3) supposedly corrupted) and have received iTunes Invoices showing that I was "billed" with amount to prove it for the downloads of already purchased Apps.... I have requested refunds from Apple and all inquiries have remained unanswered.

  • Another password problem, help please

    Hi.  I have a WRT54GS which until yesterday had been working fine.  I have it wired to my desktop computer and had wireless set up for a laptop.  I tried to hook a wii up to the router via wireless, and was unsucessful.  After giving up on that I tried to get online with the laptop when it told me that my password was incorrect.  I've gone into the settings page through internet explorer and re-entered my password several times and save changes.  When i try to connect with the laptop it still tells me that my wireless network security key is wrong.  Router is setup with WPA personal and tkip and settings are correct for that on the laptop.  I have no idea what is going on and really need to be able to use the laptop.  Thanks in advance.
    edit:
    When i am on the router's setup page, when i enter my password and then save it, the page reloads and shows more characters (black dots) than i entered.  is that just a security feature?
    Message Edited by yuengling910 on 02-04-2008 06:07 PM

    I seemed to have fixed the problem.  I ran the easy setup and downloaded setup program to usb flash drive.  Once i ran the program on the laptop, it connected right to the internet with no problems.  I don't know what happened but it works now.

  • Sql  problem - help appreciated!

    I have two tables, report_t and report_details_t.
    report_t has the following structure
    reportId fiscalYear
    ============
    1 2007
    2 2008
    Report_details_T
    reportID fund_type fund_value
    ========================
    1 direct 40
    1 indirect 20
    2 direct 30
    2 direct 5
    I am trying to generate a report using just SQL statment, the result will look like this
    report_id fund_type, 2007_fund_value, 2008_fund_value
    ====================================
    1 direct 40 0
    1 indirect 20 0
    2 direct 0 30
    2 indirect 0 5
    Is there any way achieving it?
    Thanks in advance.

    ah, ok - and was there a typo in your original set of data for the report_details_t table? there are two rows for direct for fiscal year id = 2, but one has morphed into indirect in your results.
    Assuming there was a typo:
    with    report_t as (select 1 reportid, 2007 fiscalyear from dual union all
                         select 2 reportid, 2008 fiscalyear from dual),
    report_details_t as (select 1 reportid, 'direct' fundtype, 40 fund_value from dual union all
                         select 1 reportid, 'indirect' fundtype, 20 fund_value from dual union all
                         select 2 reportid, 'direct' fundtype, 30 fund_value from dual union all
                         select 2 reportid, 'indirect' fundtype, 5 fund_value from dual)
    -- end of mimicking your data: USE SQL below:
    select rdt.reportid,
           rdt.fundtype,
           decode(rt.reportid, 1, rdt.fund_value, 0) "2007_FUND_VALUE",
           decode(rt.reportid, 2, rdt.fund_value, 0) "2008_FUND_VALUE"
    from   report_t rt,
           report_details_t rdt
    where  rt.reportid = rdt.reportid;
      REPORTID FUNDTYPE 2007_FUND_VALUE 2008_FUND_VALUE
             1 direct                40               0
             1 indirect              20               0
             2 direct                 0              30
             2 indirect               0               5Edited by: Boneist on 30-Mar-2009 15:00

  • What is the best way to remotely access my sister in laws Mac who lives in another city to help her with her computer problems?

    as stated above
    What is the best way to remotely access my sister in laws Mac who lives in another city to help her with her computer problems?

    The best way? Get her to bring it to you, especially if she makes good cakes.
    Apples Back to my Mac isn't really suitable for this - it is designed for a single person who wants their Apple ID on the system. It would mean she would have to share hers with you & you would also have to setup her Apple ID on your Mac - it is messy & causes trouble with iCloud, iTunes etc.
    You can try Messages if she is able to begin a session with you, see the 'invite to share screen' in the menus, weirdly you need to use a service that isn't from Apple.
    Messages (Mavericks): Share your screen
    It may be better if you to setup LogMeIn or GoToMyPC. They should 'dial out' & maintain a constant connection so you can login whenever the Mac is powered up. It won't, require a human to initiate the process at the other end, just be aware that the router may cause issues depending on what is configured, you may need settings to enable automatic port forwarding - it really depend on which option you choose.

  • Multiple sudden booting and other problems:  Help!

    I have experienced a sudden problem that makes me afraid to shut down my iMac until I sort it out. I have had it for five wonderful, flawless years.
    When I tried to boot today, four times it would not. I got to the grey Apple screen and a processing "clock," but it would not go beyond that in any reasonable time. I finally left it running trying to boot. It did eventually, but glacially slow. Then, there was a message that: "!You have inserted a disk containing no volumes that Mac OSX can read. To continue with the disk inserted, click ignore." However, I had NO "disk inserted."
    More wierdness followed.
    I tried to insert a memory stick to backup my hard drive, and got the same "disk containing no volumes that Mac OSX can read" message. This is the same stick onto which I have previously backed up with no problem.
    I then tried to run my McAfee virus scan, but wanetd to update it first. It does not appear to update, even though it says that it is doing so. The starting message continues to say that I last updated months ago. The Virus scan did, however, apparently run using whatever version it actually had in it, and reported only 2 noncritical errors.
    I then tried to run Disk Utility, and it won't launch. I "bounces" up an down in the Dock, but then just closes.
    I then opened iMail, and all the previous messages showed as unread, even though they actually all were read.
    So, I almost could not boot, get a weird "unreadable disk" message, can't get the drive to recognize a memory stick in order to back up to it, can't update my Virus protection, can't run Disk Utility and am getting weird iMail .
    Other things seem to be working okay, although sometimes very slowly.
    What's going on, and what do I do?
    Separate question: I want to insert a disk into my CD tray to use as a startup disk if I encounter another booting problem. Which CD do I use? Mac OSX Install Disk 1? Mac OSX Install Disk 2? (I think all the Software Restore disks include applications other than the OSX.
    Final question: how do I get the CD tray to open on the front my iMac (the "tongue" type tray out of the round base) if I have another booting problem, so that I can insert a disk to use for startup?
    HELP! (thanks)

    Ali,
    Sorry for being slow to respond. I have been trying to get things fixed with Repair Disk.
    To answer your question first, my hard drive is 74.52 GB, with 55.59GB available, so I don't think that's the problem.
    Quite a few things (but not everything) work once the hard drive boots, which is VERY VERY slow. However, any other media I try to use to backup (Memory sticks, CDs) can't be recognized. I get the "disk containing no volumes that Mac OS X can read" messae. The CD's also produced a message when I tried to name them of an "unexpected error."
    I followed your repair instructions, but it did not solve the problem. The Repair Disk effort produced an error message under "Checking catalog file" of "Keys out of order." I ran Repair Disk multiple times (at least 10x), but the same message kept coming up. I also tried running Repair Permissions, which took about four hours to run. Repair Disk produced the same error message.
    I also found an older Discussion string of messages about application Chess (installed with the basic Mac install disks) being corrupted. I trashed it. No difference.
    That message string also talked about some people having problems after installing iTunes 6.0.2, but I am running 7.0.2, and it has been on the computer about two weeks beforre any of this started.
    I will try Sherry Johnson's suggestions next.
    thanks for your help.
    Eliot

  • Connect to another SQL server from SAP

    Hi All,
    I want to connect SAP to another SQL server. Basically each day I need to take data from 2 tables in SAP tables to another sql server. I want this to be automated via a program in SAP.
    Please suggest me some methods to achieve this.
    I have searched the web and found that this is possiable, some transactions such as DBCO was mentioned, but it was not much helpful.
    Thanks a lot.
    Regards,
    Pankaj

    Moderator message - Cross post locked
    Rob

  • Another SQL Developer bug - End of file in comment

    I found another SQL Developer bug in version 3.0.0.4.
    If I try to compile some package from file (so I open file with package body in SQL Developer and assign it to some connection) with this kind of comment: /* comment */ behind end of package, I get this error
    I got Error(1250,28): PLS-00111: end-of-file in commentFunny is, that when the package is compiled directly from the database - it works.
    When I try to compile the package from file with this kind of comment --comment behind the end of package, it also works...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Hi, I think I finally got it. This looks like an ugly fat bug :)
    First, we are not using the .sql extensions. For package specification - we use .pks. For package body - we use .pkb.
    Create this script:
    CREATE OR REPLACE PACKAGE TEST_xxx AS
    PROCEDURE TEST_PROCEDURE;
    END TEST_xxx; /*0123456789*/Now save this as e.g. "TEST.pks" file. Open this file in SQL Developer and compile it. You will get the "Error(3,27): PLS-00111: end-of-file in comment".
    Now look at the result in the database -> Open the package specification from the database and you see this:
    create or replace
    PACKAGE TEST_xxx AS
    PROCEDURE TEST_PROCEDURE;
    END TEST_xxx; /*0123456789*The last slash is missing...
    Now go back to the file with the package specification and delete one letter from the comment. Compile it again... it works now.
    It looks like the length of this kind of comment is limited to 9 characters.
    The limitation is there only when:
    1) Compiling from file with different extension than .sql !!! If you rename the file to "TEST.sql", SQL Developer opens it as a script file and runs it as a script, so there is no problem with it.
    2) It has to be this kind of comment: /* */. One line comments are not limited.

  • Will Oracle pl/sql certification help me get  IT job

    Hello guys,
    I have completed my B.tech in Computer Science, I am confused a bit , Can i get a job after getting certified in Oracle Associate Pl/sql developer

    1005323 wrote:
    Hello guys,
    I have completed my B.tech in Computer Science, I am confused a bit , Can i get a job after getting certified in Oracle Associate Pl/sql developerYou may get a job after achieving Pl/sql developer OCA
    You may get a job after without achieving Pl/sql developer OCA
    You may fail to get a job after achieving Pl/sql developer OCA
    You may fail to get a job after without achieving Pl/sql developer OCA
    There are several factors involved in getting a job. And there are several ways a job may be obtained. But usually there are there stages:
    - Stage Zero: A company but has a job to offer.
    - And you need to be aware of it. - A friend may tell you, or an agency may tell you. And it must suit you for location and remuneration etc.
    - Stage one: An interview is obtained with the company.
    - Stage two: The job is offered to you rather than anyone else and you find it acceptable.
    So ... to your question:
    "Can i get a job after getting certified in Oracle Associate Pl/sql developer?"
    Well .... there is only three possible answers ... yes, no, and maybe; and maybe is probably the only correct answer, and most people will have worked this out, which means the question may have not been the best question to have asked.
    (( That said I now read the title of the thread and it says: Re: Will Oracle pl/sql certification help me get IT job)
    I have been known on occasion to have been given a question by a boss.
    And I have answered him:
    "You have given me the wrong question
    The question you should have answer me is this.
    And the answer I will give you is this."
    And the boss goes away happy
    So you you a better question would have been:
    How much will an OCA PL/SQL certification increase my chances of getting a job?
    Mind you even that question won't help you get a much better answer.
    For a proportion of jobs where PL/SQL is relevant that will help (for those where it is not it might be occasionally be a problem), for people with identical CV's it sometimes might help get to interview stage. But there are other factors as well. For instance if I was thinking of giving you a job on the basis of your post I might for example:
    - Not be impressed with an "Hello Guys" greeting ( though this is a forum so that isn't relevant here).
    - Not be impressed with you being confused.
    - etc.
    You probably need to get a good appreciation of the job market in your locality; and the numbers of applicants for each job. Which jobs you can apply for, what is your skillset and knowing youself as well.
    Sometimes an ITIL certification may be a better differentiator for some positions in business. But it will depend on the job you can think you can get.

  • (SQL*PLUS HELP) RUNNING PUPBLD OR HELPINS ASKS FOR SYSTEM_PASS

    제품 : ORACLE SERVER
    작성날짜 : 2002-04-22
    (SQL*PLUS HELP) RUNNING PUPBLD OR HELPINS ASKS FOR SYSTEM_PASS
    ==============================================================
    PURPOSE
    이 내용은 SQL*Plus 상에서 SQL*Plus command의 help를 보기 위한 방법이다.
    Problem Description
    SQL*Plus command의 help를 보기 위해서 helpins를 수행하면
    SYSTEM_PASS is not set이라는 에러 메시지가 발생하는 경우가 있다.
    이 자료는 pupbld 또는 helpins를 수행하기 전에 SYSTEM_PASS 환경변수를
    셋팅하는 방법에 대한 자료이다.
    아래와 같은 에러가 발생하는 경우 조치 방법에 대해 알아본다.
    SYSTEM_PASS not set.
    Set and export SYSTEM_PASS, then restart help (for helpins or
    profile for pupbld) installation.
    Workaround
    none
    Solution Description
    이 스크립트는 system user로 database에 connect되어 수행되어야 한다.
    helpins를 수행하기 위해서는 SYSTEM_PASS 환경변수가 셋팅되어 있어야 한다.
    NOTE
    For security reasons, do not set this variable in your shell
    startup scripts. (i.e. .login or .profile.).
    Set this environment variable at the prompt.
    1. Prompt에서 환경변수를 셋팅하기
    For C shell:
    % setenv SYSTEM_PASS system/<password>
    For Korn or Bourne shells:
    $ SYSTEM_PASS=system/<password> ;export SYSTEM_PASS
    2. Now run "$ORACLE_HOME/bin/pupbld" or "$ORACLE_HOME/bin/helpins".
    % cd $ORACLE_HOME/bin
    % pupbld
    or
    % helpins
    주의사항
    $ORACLE_HOME/bin/pupbld 스크립트와 $ORACLE_HOME/bin/helpins 스크
    립트를 수행하기 위해서는 반드시 SYSTEM_PASS 환경변수를 필요로 한다.
    Reference Document
    <Note:1037075.6>

    check it please whether it is a database version or just you are installing a client. Install Enterprize database on 2k system. I you are running a client software then you are to deinstall it.

  • Getting error while connecting Sharepoint WFE to another Sql Server 2008

    Hello All,
    I am trying to connect a sharepoint wfe to another Sql server 2008 and getting error. This is what I am trying to do.
    #Disconnecting present database serer
    Disconnect-SPConfigurationDatabase
    #Connecting to another database server
    Connect-SPConfigurationDatabase -DatabaseServer "ServerName" -DatabaseName "SharePoint_Config_nameabcd" -Passphrase $SecuredPassphrase
    Getteing below error
    Connect-SPConfigurationDatabase : Cannot open database "SharePoint_Config_nameabcd" requested by the login. The login failed.
    Login failed for user 'domain\username'.
    At line:1 char:32
    + Connect-SPConfigurationDatabase <<<<  -DatabaseServer "ServerName" -Database
    Name "SharePoint_Config_nameabcd" -Passphrase $SecuredPassphrase  + CategoryInfo : InvalidData:(Microsoft.Share... urationDatabase:SPCmdletConnectSPConfigurationDatabase) [Connect-SPConfigurationDatabase], SqlException+ FullyQualifiedErrorId
    : Microsoft.SharePoint.PowerShell.SPCmdletConnectS PConfigurationDatabaffsadss FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletConnectS PConfigurationDatabase
    Please advise to resolve the error.

    Hi,
    We have not heard from you in a couple of days.
    Just checking in to see if the information was helpful. Whether your issue is solved.
    Have a great day!
    Best Regards,
    Lisa Chen
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • My daughter has just bought me an iPad 2 from Dubai and set it all up for me but unfortunately the iMessage function doesn't seem to work. We keep getting messages,when trying to activate it, that there is a network connection problem - help!

    My daughter has just bought me an iPad 2 from Dubai and set it all up for me but unfortunately the iMessage function doesn't seem to work. We keep getting messages,when trying to activate it, that there is a network connection problem - help!

    Thank you both for your responses but my daughter was reassured by the salesman in the iStyle store (official Apple store in the UAE) that iMessages would work but conceded that FaceTime wouldn't. My iTunes account is registered in the uk and my daughter's iPhone has iMessages even though she bought it (and uses it) in Dubai. Can anyone else throw any light on this?

  • I couldn't log into my apple account on my iPad, then i couldn't unlock it resulting in it being disabled, however it's the same as my iPhones password, I then called apple, i was hung up on twice and they said it will cost £70 to fix THEIR problem, help?

    I couldn't log into my apple account on my iPad, then i couldn't unlock it resulting in it being disabled, however it's the same as my iPhones password, I then called apple, i was hung up on twice and they said it will cost £70 to fix THEIR problem, help?

    If you cannot remember the passcode, you will need to restore your device using the computer with which you last synced it. This allows you to reset your passcode and resync the data from the device (or restore from a backup).
    If you restore on a different computer that was never synced with the device, you will be able to unlock the device for use and remove the passcode, but your data will not be present.
    You may have to force iPad/iPod into Recovery Mode
    http://support.apple.com/kb/ht4097

Maybe you are looking for