Query information from the parent table and a row of child table information

I have trouble writing a query that should not really be this hard. Just my brain isn't working today. I went in circles asking myself,... "Why doesn't this work! ... Shouldn't this work"... in any case

I have a table of PEOPLE and a table of ADDRESSES. A person can have multiple addresses (one to many). We are not address the scenario of "what-if" of a single address belonging to several different people, that is close.

PEOPLE

-----------------------

Person_Id PK

First name

Last_name

ADDRESSES

------------------------

Address_Id

Subscription_type

Address_Info

Person_id FK

Address_types include: WPA, HPA, WMP, HMP, and HMA

I want to be able to pull a name of people and a specific address for the user. A person can only have one type of address that are associated with them, or they may have four different address types associated with them. The query should look to see if they have an address type of WPA, first. If they do, then enter the Address_Info for this address type. If they are not, then watch to see if they have a subscription_type of HMA. If so, enter their details. If they have not, then fair value must be set to zero.

I tried to use the case statements and decodes and I get several lines for people who have an address type of WPA and HMA. I just need a line, but I have a problem. Any help on this would be greatly appreciated. Thanks in advance. This should be simple enough for you gurus out there. Not so much for me if

Something like:

WITH AN ACE)

SELECT DISTINCT PERSON_ID,

NVL)

MAX)

SUBSCRIPTION_TYPE CASE

WHEN 'WPA' THEN ADDRESS_INFO

END

) OVER (PARTITION BY PERSON_ID).

MAX)

SUBSCRIPTION_TYPE CASE

WHEN "HMA" THEN ADDRESS_INFO

END

) OVER (PARTITION BY PERSON_ID)

) ADDRESS_INFO

ADDRESSES

WHERE SUBSCRIPTION_TYPE IN)

"WPA."

"HMA.

)

)

SELECT PERSON_NAME,

ADDRESS_INFO

PEOPLE P,.

A

WHERE P.PERSON_ID = A.PERSON_ID (+)

/

SY.

Tags: Database

Similar Questions

  • currently still have PP CS5.5 & want to install on another office, understand that I can only use one at a time. don't have a CD, can I get information from the current installation and a link to download PP CS5.5?

    currently still have PP CS5.5 & want to install on another office, understand that I can only use one at a time. don't have a CD, can I get information from the current installation and a link to download PP CS5.5?

    Download & install instructions https://forums.adobe.com/thread/2003339 can help

    -includes a link to access a page to download the Adobe programs if you do not have a disk or drive

    Find your http://helpx.adobe.com/x-productkb/global/find-serial-number.html serial No.

  • How to upgrade the parent table and child by updating the parent table

    I have a parent EMPLOYEE table that includes columns (sysid, serviceno, employeename...) sysid is the primary key, serviceno is the Unique key and I have DEPENDENT child table includes columns (sysid, employee_sysid, name, date of birth...) there still SYSID is a primary key for the table of dependants, employee_sysid is a foreign key in the EMPLOYEE table.

    Now I want to change SYSID (with the help of the sequence) in the EMPLOYEE table that they want an update in the table of people dependent

    Note: I have 10000 records in the EMPLOYEE table as I have 5 more children tables that need to update new SYSID.

    Please help me

    first disable FOREIGN KEY constraints.
    You can update Parent and child record with the help of the trigger.
    Here I give you an examlpe... It can help u.

    create a parent (id number primary key, name varchar2 (100)) table
    /
    create table child_1 (primary key id, p_id number number, date of birth, date)
    CONSTRAINT FK_id FOREIGN KEY (p_id) REFERENCES parent (ID))
    /
    create table child_2 (key primary id, p_id2, addr varchar2 number number (1000))
    CONSTRAINT FK_id2 FOREIGN KEY (p_id2) REFERENCES parent (ID))
    /

    Insert some test data for the parent tables and children.

    change the constraint to disable child_2 table FK_id2
    /
    change the constraint to disable child_1 table FK_id2
    /

    CREATE OR REPLACE TRIGGER delete_child
    BEFORE parent UPDATE ON
    FOR EACH LINE
    BEGIN
    UPDATE CHILD_1
    P_ID =:NEW.ID SET
    WHERE P_ID =:OLD.ID;
    UPDATE CHILD_2
    SET = P_ID2: NEW.ID
    WHERE P_ID2 =:OLD.ID;
    END;
    /

    then Upadte parent table primary key col and check the children tables.
    do enable constraints...

  • Select values from the db1 table and insert into the DB2 table

    Hello

    I have three databases oracle running in three different machines. their ip address is different. among the DB can access databases. (means am able to select values and insert values into tables individually.)

    I need to extract data from the DB1 table (ip say DB1 is 10.10.10.10 and the user is DB1user and the table is DB1user_table) and insert the values into DB2 table (say ip DB2 is 11.11.11.11 and the user is DB2user and table DB2user_table) of DB3 that is to have access to the two IPs DB.

    How do I do this

    Edited by: Aemunathan on February 10, 2010 23:12

    Depending on the amount of data must be moved between DB1 and DB2, and the frequency at which this should happen, you might consider the SQL * COPY more control. I think it's very useful for one-off tasks little, so I can live within its limits of the data type. More http://download.oracle.com/docs/cd/E11882_01/server.112/e10823/apb.htm#i641251.

    Change some parameter of sqlplus session are almost mandatory in order to get decent transfer rates. Tuning ARRAYSIZE and COPYCOMMIT can make a huge difference in flow. LONG change may be necessary, too, depending on your data. The documentation offers these notes on use:

    To activate the copy of data between Oracle and databases non-Oracle, NUMBER of columns is replaced by DECIMAL columns in the destination table. Therefore, if you are copying between Oracle databases, a NUMBER column with no precision will become a DECIMAL column (38). When copying between Oracle databases, you must use SQL commands (CREATE TABLE AS and INSERTION), or you must make sure that your columns have a specified precision.

    SQL * the VALUE LONGER variable limits the length of the LONG column you are copying. If all LONG columns contain data exceeds the value of LONG, COPY truncates the data.

    SQL * Plus performs a validation at the end of each successful COPY. If you set the SQL * variable more COPYCOMMIT DEFINED to a value positive n, SQL * Plus performs a validation after copying all lots n of records. The SQL * Plus ARRAYSIZE variable SET determines the size of a batch.

    Some operating environments require that the service names be placed between double quotes.

    From a SQL * Plus term on DB3, can resemble the command to move all content from my_table in DB1 to the same table in DB2

    COPY from user1/pass1@DB1 to user2/pass2@DB2 -
    INSERT INTO my_table -
    USING select * from my_table
    

    Note the SQL code * more line-continuation character ' - '. It is used to escape the newline character in a SQL * Plus command if you do not have to type all on one line. I use it all the time with this command, but I can't locate the documentation on that right now. Maybe someone else can put their finger on it.

    There are other ways to accomplish what the command copy and it is not without its quirks and limitations, but I find that there is usefulness in an Oracle Toolbox.

  • BULL, INSERTION IN THE PARENT TABLE AND THE CHILD TABLE

    Hi all

    We use bulk insert to improve performance. How to use this concept when I insert the records parent in table parent and child?

    example... I have a procedure that accepts the array of student objects

    each student object is defined as *(student name, student age, course_object_array) *.

    the 3rd element course_object_array is defined as *(coursename,course fee,facultyname) *.

    a student can be associated with several courses

    Now, I have to insert the data into two tables namely students (studentname, studentage and student_number)
    courses (course_id, coursename, fees, facultlyname, student_number)

    I use sequences to fill the columns student_number and course_id.

    If I use bulk insert, and insert all the records in the parent table how do I the association for each record of a child. How will I know what child folder must be associated with which of the parents?

    Concerning
    REDA

    raj_fresher wrote:
    Hi thanks for the reply Solomon.

    I actually know about the bulk collect and for all...

    Have you read that FOR ALL with in fact BULK COLLECT? It will allow you to bulk insert via for ALL with VOTING student_numbers attributed to each student placed in a collection. Then, you will use this collection collection of course list to fill the RACE table.

    SY.

  • How can I get the second and third highest salary from the emp table

    How can I get the second and third highest salary from the emp table in the ecah Department
    SQL> ed
    Wrote file afiedt.buf
    
      1  select empno, ename, sal, deptno
      2  from (
      3    select empno, ename, sal, deptno, dense_rank() over (partition by deptno order by sal desc) as rn
      4    from emp
      5    )
      6* where rn in (2,3)
    SQL> /
    
         EMPNO ENAME             SAL     DEPTNO
    ---------- ---------- ---------- ----------
          7782 CLARK            2450         10
          7934 MILLER           1300         10
          7566 JONES            2975         20
          7876 ADAMS            1100         20
          7499 ALLEN            1600         30
          7844 TURNER           1500         30
    
    6 rows selected.
    
    SQL>
    
  • From the versioned tables link to another diagram

    Hello!

    We are currently assessing the mechanisms of synchronization of data as possible for a future database that must use data from a database of existing B.
    option 1 is the simplest: export data from B, import in A and you're done. the problems are of course used those like arguing with Exim, how up-to-date the data is, etc.
    However, we are more interested in option 2: link to the tables of a B. If we are not wrong here we could establish this with the help of dblink and synonymous.
    done importand is arrays in B are versioned with OWM. is it in any way possible to link to those who in this case? and if so, how selection of work/savepoint space be treated?
    We suspect that this is not possible, at least not if A base table are not versioned as well. or you would need to omit true foreign keys when the referencing of the versioned tables in B of A, which is not exactly good either.

    Thanks for the advice in advance!

    Kind regards

    Andreas

    Hi Andreas,

    You can use synonyms and links. GotoWorkspace works the same as it would for the local database. Just run it on the remote database.

    For example,.
    SQL > exec dbms_wm. GotoWorkspace@dblink ('Workspace1');

    You should be able to use tables from different databases in the same query. However, it is not any child support for foreign key constraints where the tables are set to different databases and only the tables is transferred. In the case, the parent table must be part of the same db as the child.

    Kind regards
    Ben

  • XML from the Oracle Table data

    Hi all

    I'm new to this network. I'm also new to oracle XML package. I want a help with the query below.

    CREATE TABLE EMP (ID NUMBER PRIMARY KEY, NAME VARCHAR2 (10), TELEPHONE NUMBER);

    INSERT INTO EMP (ID, NAME, PHONE) VALUES (11, 'Joy', 1234);
    INSERT INTO EMP (ID, NAME, PHONE) VALUES (22, 'Mike', 5678).
    INSERT INTO EMP (ID, NAME, PHONE) VALUES (33, "Jason", NULL);
    COMMIT;

    I want to export data from the EMP table in an XML file with the format below.

    Power required:

    <? XML version = "1.0" encoding = "UTF-8"? > < Joy STATICDATA > < EMP > < ID > 11 < /ID > < NAME > < / NAME > < / EMP > < / STATICDATA >
    <? XML version = "1.0" encoding = "UTF-8"? > < Mike STATICDATA > < EMP > < ID > 22 < /ID > < NAME > < / NAME > < / EMP > < / STATICDATA >
    <? XML version = "1.0" encoding = "UTF-8"? > < Jason STATICDATA > < EMP > < ID > 33 < /ID > < NAME > < / NAME > < / EMP > < / STATICDATA >

    I used some XML functions and you wrote the following query.

    Select XMLROOT (XMLELEMENT (staticdata, XMLELEMENT (EMP, XMLELEMENT(ID,ID), XMLELEMENT(NAME,NAME))), version "1.0" encoding = "UTF - 8') xml EMP;

    my query output:

    <? XML version = "1.0" encoding = "UTF-8"? >
    < STATICDATA >
    < EMP >
    < ID > 11 / < ID >
    Joy of < NAME > < / NAME >
    < / EMP >
    < / STATICDATA >
    <? XML version = "1.0" encoding = "UTF-8"? >
    < STATICDATA >
    < EMP >
    < ID > 22 / < ID >
    < NAME > Mike < / NAME >
    < / EMP >
    < / STATICDATA >
    <? XML version = "1.0" encoding = "UTF-8"? >
    < STATICDATA >
    < EMP >
    < ID > 33 / < ID >
    Jason < NAME > < / NAME >
    < / EMP >
    < / STATICDATA >


    But I want the out as the power required above. all records in a single line. can someone help me achieve the desired output. also can I export all columns of the table with something like select * from the table in the XML file?

    Thank you
    Delobelle

    Don't know why you need it on a single line, but you could:

    Select XMLTYPE (REGEXP_REPLACE (XMLROOT (XMLELEMENT (staticdata, XMLELEMENT (EMP, XMLELEMENT(ID,ID), XMLELEMENT(NAME,NAME))), version "1.0" encoding = "UTF - 8'), CHR (10) |)) ' *<><'))>
    FROM EMP;

    SY.

  • referential integrity with a view to the parent table

    Is it possible to create a foreign key that uses a view as the parent table?

    CREATE TABLE one
    + (id NUMBER CONSTRAINT a_pk PRIMARY KEY, +)
    name VARCHAR2 (32));

    CREATE TABLE b
    + (name of the b_pk VARCHAR2 (32) CONSTRAINT PRIMARY KEY, +)
    address VARCHAR2 (32));

    CREATE VIEW b_view AS SELECT * FROM b;

    ALTER VIEW b_view ADD CONSTRAINT b_view_pk PRIMARY KEY (name) DISABLE NOVALIDATE;

    ALTER TABLE an ADD CONSTRAINT a_fk
    B_view (name) REFERENCES of FOREIGN KEY (name);

    "After issuing the last alter statement I get the error: ' ORA-02270: no unique or primary key corresponding to this list of columns.

    If I use just the table b of referential integrity, everything works. Is this just a limitation of the use of the view with a PK defined as disable novalidate? Is there a workaround to use the view?

    Thank you
    mcslain

    AFAIK, you can create constraints on views, purely for the sake of documentation.
    Sense: these constraints are never implemented, they must be defined using the NOVALIDATE keywords to DISABLE.

    And since these constraints, say the b_view_pk in your case, are DISABLED/NOVALIDATE, you cannot have a foreign key (ENABLED), which points to them.

    Pouvez have you a foreign key pointing at them is DISABLED/NOVALIDATE too, however.
    But I bet it's not what you want.

  • DVD drive icon has disappeared from the Device Manager and my computer

    DVD drive icon disappeared from the Device Manager and my computer. I m using window 7. How can I get it back.

    Ashwani Hello,

    Thanks for posting on Microsoft Community.

    There are various reasons why a CD or DVD drive may not be detected. I would like to ask all of the steps in the Microsoft Article describes a troubleshooting and check if they help to resolve the issue.

    Your CD-ROM or DVD drive is not recognized by Windows or other programs

    Note:

    Before editing a registry key or subkey, we recommend that you export, or make a backup copy of the key or the subkey. You can save the backup copy to a location that you specify, for example, a folder on your hard drive or a removable storage device. If you make changes that you want to cancel, you can import the backup copy. For more information about backing up the registry, please see the link below.

    How to back up and restore the registry in Windows

    Hope that advice is useful. Let us know the State of the question, so that we can guide you further.

  • I tried to set the parental control and received this message: because this computer is connected to a domain, Parental controls are not available.

    I have the internet Charter.  I am a home user.  I tried to set the parental control and received this message: because this computer is connected to a domain, Parental controls are not available.  Again, I am a home user.  What does that mean?

    Hello

    1. which user account you are using for Parental control (Please note that you cannot apply parental controls on a user admin account? It can be applied to standard user only accounts)?

    2 have you made changes on the computer before this problem?

    I ask through the following article to find out how to set up Parental controls:

    http://Windows.Microsoft.com/en-us/Windows7/products/features/parental-controls

    http://Windows.Microsoft.com/en-us/Windows7/set-up-parental-controls

    After completing the above links persist issue please fallow the mentioned below of the methods.

    Method 1: Disable UAC (User Account Control) and check the result
    See http://Windows.Microsoft.com/en-us/Windows7/how-do-I-change-the-behavior-of-user-account-control-by-using-the-slider

    Note: You must restart your computer when you enable or disable UAC. Change levels of notification does not require that you restart your computer.

    Important: Enable UAC after you complete the steps.

    Method 2: If the problem persists, try to set the parental control in safe mode and check the result. If you are able to apply settings in safe mode, this means that some program is causing this problem, mainly the security software.
    See http://Windows.Microsoft.com/en-us/Windows7/start-your-computer-in-safe-mode  

    Hope the above information is helpful.

  • missing parenthesis in insertion into separate lines select the table from the other table

    Hello

    could you help me with the following question?

    I have the following tables

    CREATE TABLE table1)

    ID varchar (12),

    col2 varchar (10),

    COL3 varchar (10),

    level varchar (10))

    CREATE TABLE table2)

    Id2 varchar (12)

    A varchar (10),

    B number (1)

    CONSTRAINT PRIMARY KEY PK (ID2, is));

    INSERT INTO table2 (ID2, A, B) SELECT ID, col2

    MAX (CASE WHEN level = "level 1" then 1

    level = 'level 2' then 2

    Level = 3 then 'niveau3') as colIN3)

    FROM table1 GROUP BY ID2, a.;

    the first table have duplicates as follows:

    Id2 COL2 COL3 level

    A1 pepe football level1

    A1 pepe football level2

    A1 pepe football level1

    A1 pepe basket level2

    A1 pepe pingpong level3

    the output should be selected with unique key (ID2, col3) lines and the level must be the greatest.

    Id2 COL2 COL3 level

    A1 pepe football level2

    A1 pepe basket level2

    A1 pepe pingpong level3

    The output of the script tells me the following messages:

    -lack of right parenthesis referring to the max function.

    Thanks adavance.

    Kind regards

    Hello

    Remember the ABC's of the GROUP BY:

    When you use a GROUP BY clause or in an aggregate function, then all in the SELECT clause must be:

    (A) a ggregate function,

    (B) one of the expressions "group By."

    (C) adding to C, or

    (D) something that Depends on the foregoing.  (For example, if you "GROUP BY TRUNC (dt)", you can SELECT "TO_CHAR (TRUNC (dt), 'Mon - DD')").

    To ask him, there are 5 columns in the SELECT clause.  The last one is a function MAX (...); It is an aggregate, is not serious.

    The first 2 columns are also named in the GROUP BY clause, so that they are well.

    The other 2 columns, country and internal_Id do not match any of the above categories.  These 2 columns cause the error.

    There are many ways to avoid this error, each producing different results.  You could

    • remove these 2 columns in the SELECT clause
    • Add these 2 columns in the GROUP BY clause
    • use the aggregation such as MIN, 2-column functions
    • remove the country from the SELECT clause and add internal_id to the GROUP BY clause
    • remove the internal_id from the SELECT clause, and add countries to the GROUP BY clause
    • ...

    What are the results you want?

    Whenever you have a question, please post a small example of data (CREATE TABLE and INSERT statements) for all the tables involved, so people who want to help you can recreate the problem and test their ideas.  Also post the results you want from this data, as well as an explanation of how you get these results from these data.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

  • Hello someone can help me please? I received a call from the CTIC Tech and they gave me Anti Malver software. I would like to ask you about it?

    Hello

    can someone help me please? I received a call from the CTIC Tech and they offered me an Anti Malver software which I paid 179 euros. I would like to ask you about it?

    These phone calls, e-mails or popup messages will ALWAYS be a scam.

    You have been scammed.

    Based on your other posts, you aapear have called these criminals. You allow to access your computer?

    Note: Please stop rather create several threads with the same question, answer in one of the many other threads.

  • HP Envy 4500: Print jobs disappear from the print queue and not print (Windows 7).

    I just bought a HP Envy 4500 printer,

    When you attempt to print from a PC with windows 7 OS home pro (64-bit), the print job appears in the queue and then disappears, but the printer does not print anything.

    Everything else seems to work very well know

    • The printer prints the internal test page
    • The printer does print when you use iPad2
    • The printer does print when you use ePrint
    • The PC recognizes and communicates with the printer (tried with USB connections and wireless)
    • Analysis feature works very well - when initiated from the PC and printer

    I tried

    • uninstalling and reinstalling the software (several times using software from different sources)
    • restart the printer queue service
    • Disabling the firewall
    • running printing HP and doctor Scan
    • following the instructions described here (the question is the same but the different operating system):

    Print jobs disappear from the print queue and print (Windows 8)

    • combinations of all of the above

    Absolutely no joy in any of them, and in spite of more than 2 hours of research on Google and forums search I can't find a solution.

    HP... can you give me a solution or is that goes back to the shop?

    Well I finally worked on the fix myself by trial and error.  I changed the security settings for 'All' and 'Creator owner' to 'Print' and "Administer Documents".  Why on earth they were not automatically allowed as part of the installation, I couldn't really say.

    Hope this helps someone else with a similar problem.

  • no more WiFi which extends from the airport express and Time capsule

    I have no more WiFi which extends from the express airport and Time capsule.

    and once it worked...

    airportconfiguration-app also works, but the graphic display allows to have a straight white line. now, it's one interrupted...

    Your unbroken lines in airport show connections ethernet utility... broken lines show the wireless connections.

    So it depends on the extend method you used.

    I think at this moment, things are configured wrongly... for some strange reason things happens and elements on a stand-alone basis, return to a default mode.

    The best way to manage it is full factory reset on everything... and repeat the installation.

    I have no more WiFi which extends from the express airport and Time capsule.

    It seems to me that you extend a NON-APPLE router... in this case, your Apple routers must connect by ethernet and create a wireless network. Routers Apple cannot extend the NON-APPLE router wired.

    The express could extend the TC or visa versa... by wireless...

    Then I suggest say us what is the main router in the network?

    You have connected by ethernet to the TC or Express or both?

    If so please reset completely the two elements and try again. Make sure they are in bridge mode... It's the network tab. Router Mode is turned off.

    And your wireless tab is configured to create a wireless network...

    Use the same name (SSID) and even the security setting and the password as the main router to network roaming (extend wireless ethernet).

    If the Express and transport CANADA are the same, both will have this configuration... If the express extends to wireless then it should NOT be connected to all the way to ethernet... (sequel to wan side at least) and it will be set to expand wireless on the wireless tab.

Maybe you are looking for