Can I do this with a single query?

I have table A like
Table A
node_id node_no
N1......01
N2......02
N3......03
N4......04
N5......05
Using Table A, I need to populate the Table B having relationship like
Table B
link_id pred_node_id succ_node_id
L1..... N1...........N2
L2..... N2...........N3
L3..... N3...........N4
L4..... N4...........N5
There is a sequencial link between the nodes. We need to arrange the nodes ordered by their node_no so that the sequencial like for nodeds would be 01,02,03,04,05,.... Between each pair of ordered nodes, a link is to be created i.e.
a Link L1 links node N1 (pred_node) and N2 (succ_node),...
Do I have any ways so that I can populate the table B with a single insert...select statement?

SQL> create table tablea
  2  as
  3  select 'N1' node_id, '01' node_no from dual
  4  union all
  5  select 'N2','02' from dual
  6  union all
  7  select 'N3','03' from dual
  8  union all
  9  select 'N4','04' from dual
10  union all
11  select 'N5','05' from dual
12  /
Table created.
SQL> create table tableb(link_id varchar2(10), pred_node_id varchar2(10),succ_node_id varchar2(10))
  2  /
Table created.
SQL> insert into tableb
  2  select * from
  3  (
  4  select 'L'||to_number(node_no) link_id,node_id,lead(node_id) over(partition by 1 order by to_number(node_no)) succ_node_id
  5  from tablea
  6  )
  7  where succ_node_id is not null
  8  /
4 rows created.
SQL> select * from tableb;
LINK_ID    PRED_NODE_ SUCC_NODE_
L1         N1         N2
L2         N2         N3
L3         N3         N4
L4         N4         N5
SQL>

Similar Messages

  • How can I update the table with a single query for...

    I have a table with columns C1 and C2.
    C1 C2
    A1 null
    A1 null
    A1 null
    A1 null
    A2 null
    A2 null
    A2 null
    A3 null
    A4 null
    A4 null
    I want to update my table with a single query so that I would have data like
    C1 C2
    A1 1
    A1 2
    A1 3
    A1 4
    A2 1
    A2 2
    A2 3
    A3 1
    A4 1
    A4 2
    The updated column C2 has the values like serial no grouped on the column C1.

    SQL> create table mytable
      2  ( c1 varchar2(2)
      3  , c2 number(2)
      4  )
      5  /
    Tabel is aangemaakt.
    SQL> insert into mytable (c1)
      2  select 'A1' from dual union all
      3  select 'A1' from dual union all
      4  select 'A1' from dual union all
      5  select 'A1' from dual union all
      6  select 'A2' from dual union all
      7  select 'A2' from dual union all
      8  select 'A2' from dual union all
      9  select 'A3' from dual union all
    10  select 'A4' from dual union all
    11  select 'A4' from dual
    12  /
    10 rijen zijn aangemaakt.
    SQL> select * from mytable
      2  /
    C1                                     C2
    A1
    A1
    A1
    A1
    A2
    A2
    A2
    A3
    A4
    A4
    10 rijen zijn geselecteerd.
    SQL> merge into mytable t1
      2  using (select c1
      3              , row_number() over (partition by c1 order by null) rn
      4              , rowid rid
      5           from mytable
      6        ) t2
      7     on (t1.rowid = t2.rid)
      8   when matched then
      9        update set c2 = rn
    10   when not matched then
    11        insert values (null,null)
    12  /
    10 rijen zijn samengevoegd.
    SQL> select * from mytable
      2  /
    C1                                     C2
    A1                                      1
    A1                                      2
    A1                                      3
    A1                                      4
    A2                                      1
    A2                                      2
    A2                                      3
    A3                                      1
    A4                                      1
    A4                                      2
    10 rijen zijn geselecteerd.Regards,
    Rob.

  • Insert into two tables with a single query (same ID)

    Hello,
    I want to insert two tables at the same time ( with a single query) provided that both records get inserted with the same id. How do I do this?
    Table Movies
    id
    name
    Table Category
    movie_id
    cat_typea) Insert into first table, retrieve the id (may be by using my_sequence.currval and then insert into another table.
    issue: Makes three query to the db, I am also guessing that when multiple people try to insert there will be an issue, I might be wrong.
    I don't have any other idea.
    Greatly appreciated!

    Why don't use multitable insert ? It's available from 9i.
    A sequence.nextval will return the same value within the whole instruction
    so all records can be inserted with the same id.
    Look at this example:
    DROP TABLE A;
    DROP TABLE B;
    drop sequence a_seq;
    CREATE TABLE A(
      ID NUMBER,
      FIRSTNAME VARCHAR2(50)
    CREATE TABLE B AS
    SELECT id, firstname lastname FROM a;
    CREATE SEQUENCE a_seq
    START WITH 1;
    INSERT ALL
    INTO A(ID, FIRSTNAME) VALUES(A_SEQ.NEXTVAL, FNAME)
    INTO B(ID, LASTNAME) VALUES(A_SEQ.NEXTVAL, LNAME)
    SELECT 'fname ' || LEVEL FNAME, 'lname ' || LEVEL LNAME
    FROM DUAL
    CONNECT BY LEVEL < 10
    COMMIT;
    SELECT * FROM A;
    SELECT * FROM b;
    DROP TABLE A succeeded.
    DROP TABLE B succeeded.
    drop sequence a_seq succeeded.
    CREATE TABLE succeeded.
    CREATE TABLE succeeded.
    CREATE SEQUENCE succeeded.
    18 rows inserted
    commited
    ID                     FIRSTNAME                                         
    3                      fname 1                                           
    4                      fname 2                                           
    5                      fname 3                                           
    6                      fname 4                                           
    7                      fname 5                                           
    8                      fname 6                                           
    9                      fname 7                                           
    10                     fname 8                                           
    11                     fname 9                                           
    9 rows selected
    ID                     LASTNAME                                          
    3                      lname 1                                           
    4                      lname 2                                           
    5                      lname 3                                           
    6                      lname 4                                           
    7                      lname 5                                           
    8                      lname 6                                           
    9                      lname 7                                           
    10                     lname 8                                           
    11                     lname 9                                           
    9 rows selected

  • Can you do THIS with Captivate ? ...

    Hi,
    I'm new to Adobe Captivate and am using the 30 day trial to see if it does what I need it to do.
    I need to create a test as follows:
    60 questions, split into sections.
    I need a small button for each question, numbered 1 - 60 aligned vertically in one line down the left of the page, so there would need to be some scrolling as 60 buttons would go off the screen.
    Pushing each button would select a multiple choice question from a random pool. eg. Push button No. 5 and a random question would be there. Push 6 and there's be a different question, but if you pushed 5 again, the same question would be there as before. This enables the person being tested to skip back and fore between questions by clicking the buttons.
    There may be numerous sections to each test.
    eg.
    Car Engines
    Car Bodywork
    Steering
    Suspension etc. etc.
    So, questions 1 - 8 say may be picked randomly from the 'Car Engines' question pool.
    Questions 9 - 19 say may be picked randomly from the 'Car Bodywork' question pool. etc. etc.
    At the end of the test, I need the results to be displayed such as:
    Car Engines - 76%
    Car Bodywork - 52%  etc.
    I'd also like a simple bar chart representation if possible.
    Hope this is clear.
    I'd be very grateful if somebody could advise if this type of test scenarion can be created with Captivate.
    I'm prepared to learn to use Captivate if it can be done, but do not want to waste my time if Captivate doesn't have the capability to create this type of test.
    Grateful for any advice.

    Captivate won't give you exactly what you've described straight out of the box.  But then, neither will any other authoring tool that I'm aware of.
    Scrolling Navigation Buttons
    The Captivate screen does not scroll.  You need to think of it as being like a movie you watch on TV, not as an HTML web page.  There are widgets available to give some scrolling of text in captions, but not something that would provide navigation on each and every quiz slide with buttons to jump to any question in the quiz.
    Question Pools
    Captivate can have any number of question pools associated with a single project file, but you have to set up how many questions will come from a given pool before you publish the project. When the project loads into the user's browser, the randomisation is done to select the particular questions from each pool that will appear in the movie at runtime and is then fixed for the duration of that runtime.  You can't control it and perform more randomisation via clicking of buttons. Basically, your navigation buttons are just intended to take you to particular question slides.  Which quiz question appears on that slide at runtime is totally dependent on the randomisation done from the question pool.
    So if you have 5 question pools, each with 20 questions, but only want ten question from each pool to appear in your published project, you can easily do this with Captivate.
    NOTE: One other thing you need to be aware of is that once your user answers a question and moves off that slide, their answer will be locked and cannot be changed until the Retake the Quiz or relaunch the lesson.  So although Captivate can be configured to allow backward movement, it does not necessarily allow your user to go back and change their answers to questions previously answered.
    Quiz Results
    Captivate considers all questions or scored objects in a project file to be part of its Quiz Scope.  This scope begins on the slide containing the first scored element, and goes until the last scored element.  A project file can have only one Quiz Results slide which will show scoring data from all objects in the Quiz Scope.
    If you want to have scoring displayed separately for certain sections of your quiz (Car engines, Car bodywork, etc) you will need to use one of Captivate's more advanced techniquest using Advanced Actions and Variables.  It can be done out of the box, but it takes time to achieve the required scripting.
    Captivate does not have bar charts as standard screen objects.  Once again, you could use some fancy Advanced Actions and Variable scripting to rig up something that looked similar.  But it would take yet more time.
    I hope this helps with your decision.

  • I have my iTunes library on an external HD because it is too big for my iMAC 500GB HD. I want to backup my external HD. Can I do this with any Apple cloud product or should I look elsewhere? Also is it worth just buying another external HD to back up

    I have my iTunes library on an external HD because it is too big for my iMAC 500GB HD. However, it is not backed up, so I need a solution to backup my external HD. Can I do this with any Apple cloud product or should I look elsewhere for cloud products? Will it be cheaper/easier just to buy another external HD to back up my existing external HD? Thanks

    I don't know if this is me adding files to iTunes when the external wasn't connected
    it is.
    is it OK to just keep deleting that library on the Air?
    i wouldn't - at least not until i
    mount the external
    point iTunes media folder location back to the external via preferences > advanced
    consolidate my library via file > library > organize library
    The ntfs hasn't seem to be causing any problems, but I've always wanted to know.
    in order for your Mac to write to NTFS drives, it needs some help by installing e.g. the NTFS 3G driver. apparently that or something similar is installed on your Mac already. preferably, it would be formatted for Mac but then windows machines would need to have e.g. MacDrive installed to recognize the drive.

  • How do you set up multiple users? Netscape use to let me choose which profile to start. Can I do this with Firefox and can I have email linked to each individual user/login? How?

    Netscape use to let me choose and create new profiles. after clicking on the icon for netscape i was prompted for which user profile i wanted. can i do this with firefox? also, each user profile was linked with its respective email account. can i do this through firefox as well? I need help. i have tried setting up firefox before and since i couldn't accomplish this i had given up but netscape is so old and most sites cause it to crash, i need a solution. i have 2 main profiles and 2 different email addresses. any advice or help, even not firefox related would be great

    Firefox doesn't have the same type of interface for the Profile Manager that Netscape did. You might want to look at SeaMonkey ''(which uses the same Mozilla Gecko code as Firefox has)''.
    http://www.seamonkey-project.org/

  • Can I do this with .Mac?

    I work at a nonprofit organization with four offices. I would like to use photocasting to make it easy for the other offices to send me photos. But, we only have two .Mac accounts. I'm using one. One computer in each of the other three offices is set up with the other .Mac account.
    I started by setting two of them up on iPhoto and one was able to publish a photocast. I was able to subscribe to it. But the second one didn't work so well. And then both stopped working. I would get a message saying that the photocast did not exist on that .mac account. However when I searched for them in the iDisk they were actually there.
    I'm basically wondering if the problem is just that I can't do this with one .Mac account or if I should be looking for some other problem. If anyone has an idea about this I would appreciate the advice.

    mchavo:
    Set up your Public folder with a user name and password and have the other offices access that folder on your iDisk to upload their photos in folders with appropriate titles to let you know where they came from and the date. The senders could archive the folder of photos, zip them, and send. Might make sending a bit quicker.
    Have you tried emailing or are there too many and too big?
    Do you Twango?
    TIP: For insurance against the iPhoto database corruption that many users have experienced I recommend making a backup copy of the Library6.iPhoto database file and keep it current. If problems crop up where iPhoto suddenly can't see any photos or thinks there are no photos in the library, replacing the working Library6.iPhoto file with the backup will often get the library back. By keeping it current I mean backup after each import and/or any serious editing or work on books, slideshows, calendars, cards, etc. That insures that if a problem pops up and you do need to replace the database file, you'll retain all those efforts. It doesn't take long to make the backup and it's good insurance.
    I've written an Automator workflow application (requires Tiger), iPhoto dB File Backup, that will copy the selected Library6.iPhoto file from your iPhoto Library folder to the Pictures folder, replacing any previous version of it. You can download it at Toad's Cellar. Be sure to read the Read Me pdf file.

  • Hi, Unfortunately my Laptop has died (which had my iTunes on it). I want to ensure my music on my iPhone 5 and my iPad Air are backed up. Also, I want to sort my music in the way I used to with iTunes. How can I do this with just these two devices?

    Hi, Unfortunately my Laptop has died (which had my iTunes on it). I want to ensure my music on my iPhone 5 and my iPad Air are backed up. Also, I want to sort my music in the way I used to with iTunes. How can I do this with just these two devices, i.e. NO Computer? Can the iCloud help? Why can't I download iTunes (i.e. my library as I saw it on the computer) to these devices? Thanks to anyone who can help me here.

    You can change the email address of one's appleID...
    I'd recommend changing moms email to yours to get a good backup on the Mac
    Then switch mom's back to hers
    Then change your account to the same email you used.
    I've done something similar when I needed to update my Apple account (one ID changing email addresses and phone)

  • Can I partition my hard drive to hold Windows 8 (Beta), instead of Windows 7, and can I do this with an external CD drive?

    I have a late 2008 Macbook Pro with Mac OS X 10.8 Mountain Lion installed, but my CD drive inside my computer is damaged*, and it's far cheaper to buy an external CD drive than to repair it entirely. Before I do either, I would like some grasp of whether or not it's worth my time and money, as I've yet to order the external drive or make a genius bar appointment.
    Also, the reason I'm choosing Windows 8 (Beta) is because it's free.
    *I dropped my computer once two years ago. I haven't even used my CD drive until recently when trying to install Windows 8. I assume the drop was the issue. I've used compressed air to remove dirt/dust as well as resetting the PRAM multiple times and nothing seems to work, but I'm not worried about it.
    Thank you.

    Can I partition my hard drive to hold Windows 8 (Beta), instead of Windows 7, and can I do this with an external CD drive?
    No and No.
    1: Apple only supports Windows 7 at this time in BootCamp (direct install into a bootable partition) because Win 8 is in Beta and no Mac hardware drivers are available yet from Apple for Windows 8.
    2: You can't install Windows from a external cd drive into BootCamp, it has to be a internal one far as I know, perhaps a USB will work I don't know.
    Yes:
    1: You can download and install Windows 8 Beta into a the free virtual machine software called VirtualBox, which Windows 8 will run in a window in OS X. This is better as it's still in Beta and Windows Beta releases will expire. Plus Windows 8 is a pain in the behind and you will want to be able to have VirtualBox or OS X be able to regain control over the computer.
    http://osxdaily.com/2012/03/03/try-windows-8-consumer-preview-virtualbox/
    Windows in BootCamp or Virtual Machine?

  • My iPhoto icon has a cross over it, when i open it, it You have "iPhoto" 9.2.1. you can't use this with this version of OSX? it used to work ?what's gone wrong?

    my iPhoto icon has a cross over it, when i open it, it You have “iPhoto” 9.2.1. you can't use this with this version of OSX? it used to work ?what's gone wrong?

    iPhoto 9.2.3 is incompatible with MacOS 10.9.3 Mavericks. If you are running Mavericks on your system you need to update iPhoto to 9.5.1. Only, the problem is, that this version is no longer available at the App Store.
    The easiest way to get a compatible iPhoto version in that case would be to upgrade to Yosemite, MacOS X 10.10, and then download the most recent iPhoto version from the AppStore, iiPhoto 9.6, like LarryHN suggested.
    If you cannot download iPhoto after upgrading to iPhoto 9.6 post back.

  • I want to communicate with a hearing impaired partner who has bluetooth compatible hearing aids.  Can I do this with an iPhone?

    I want to communicate with a hearing impaired partner who wears bluetooth enabled hearing aids.
    Ideally, I would use an bluetooth mic via an iPhone that would work directly with her hearing aids.  This would be done primarily in home and work environments.  
    Can I do this with an iPhone?  If so, how?
    Thanks,
    Bob

    troubleshooting messae http://support.apple.com/kb/ts2755

  • How can I put a face on another body and make it look real? Can I do this with photoshop elements 13.

    How can I put another face on another body that I find on the web? Can I do this with photoshop elements 13? And If so can I make it look real?

    See this link:
    Google

  • I have a Powerbook G4. I want to use an iMac desktop, the model that is shaped llike a lamp, as an external monitor. Can I do this with firewire or USB cable or do I have to have a different cable?

    I have a Powerbook G4. I want to use an iMac desktop, the model that is shaped llike a lamp, as an external monitor. Can I do this with firewire or USB cable or do I have to have a different cable?

    You need a network connection and a product such as ScreenRecycler. All such products require a bootable OS on the iMac.
    (58362)

  • I have a new MacBook Air with Yosemite (no CD/DVD capacity). I want to install Photoshop Elements 6. Can I do this with the serial number? If pse 6 is not compatible, can I upgrade to pse 7. I do not need pse 12 or 13.

    I have a new MacBook Air with Yosemite (no CD/DVD capacity). I want to install Photoshop Elements 6. Can I do this with the serial number? If pse 6 is not compatible, can I upgrade to pse 7. I do not need pse 12 or 13

    I cannot answer regarding compatibility, but there is no download available for PSE6 if you would need one for this.  You might be able to copy the installation files from a disk to some other removable media that the machine accepts.  Upgrading to PSE7 would not be possible mainly because Adobe does not sell older versions of their software.

  • I need to change a photo into a video file in order to post on youtube. How can I do this with my mac?

    I need to change a photo into a video file in order to post in youtube. How can I do this with my mac mini?

    When I go to import, the choices are :
    movies
    camera archive
    imovie for IOS
    imovie for HD
    It refuses to import a photo with any of these choices, which is located on the desktop or in a folder. It's a regular .jpg
    There are instructions to drag it. I put it there, and it bounces right back. The photo will not stay.
    I just need this one picture to go on so I can post a meditation on youtube.  It doesn't come from a camera.

Maybe you are looking for