Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Algorithm for adding tree type structure in a database

  1. Aug 25, 2009 #1
    In an SQL table I am working on for an assignment, the data are arranged liked this:

    pk name num
    A bob 234
    A joe 2323
    A sam 999
    B eli 233
    C bob 234
    C joe 2323
    D joe 399

    I was wondering, does anybody here know what code I can use to do an INSERT for each letter "A", "B", "C", etc., just once? In other words how can I add a line to the table that looks like this:

    x ana 123

    .. where x is the letter of the primary key (pk)?

    The resulting table would have to look like this:

    pk name num
    A bob 234
    A joe 2323
    A sam 999
    A ana 123
    B eli 233
    B ana 123
    C bob 234
    C joe 2323
    C ana 123
    D joe 399
    D ana 123

    I can complete the assignment without this code, but still I am curious to how it can be done. I do have a strong hunch that it can be done, and maybe I have done it before in one of my database classes. The caveat to this particular assignment is that I cannot use PL/SQL, PHP, or some other language besides just plain SQL to do the processing.

    cswave
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted



Similar Discussions: Algorithm for adding tree type structure in a database
  1. Binary tree (Replies: 5)

  2. Distributed database (Replies: 6)

Loading...