Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Senior Coder
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    1,063
    Thanks
    2
    Thanked 0 Times in 0 Posts

    table within a table (2D table?)

    Is it possible to have a table that contains many other tables?
    ex:
    table1
    contains these items : table1.1, table1.2, table1.3, etc.
    table2
    contains these items : table2.1, table2.2, etc.

    Kind of like 2D arrays...
    And if it is possible, how do I do it?
    Thanks
    Shawn

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well a table by definition is 2D. (A 2D array is ultimately a table)

    You can have a table with one column, such that every row has an attribute which holds the id of a record in another table. Or perhaps holds the name of another table instead?

    I dunno, why the heck would you want to do that anyway?

    Sadiq.

  • #3
    Senior Coder
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    1,063
    Thanks
    2
    Thanked 0 Times in 0 Posts
    What I meant is:

    table1
    row1 | col1 | col2 | col3
    row2 | col1 | col2 | table 2
    etc

    table2
    row1 | col1 | col2 etc.

    The third collumn of the second row of the first table contains another table.

    I wanted this for a forum.
    table one contains:
    row1 | ThreadID | ThreadAuthor | Posts (this is table2)

    table2 contains:
    row1 | PostID | PostAuthor
    row2 | PostID | PostAuthor
    ect..

    the equivalent with js arrays:

    var threads = new Array(thread1,thread2);
    var thread1 = new Array("1","shlagish",posts1);
    var thread2 = new Array("2","shlagish2",posts2);
    var posts1 = new Array(posts1_1,posts1_2);
    var posts2 = new Array(posts2_1,posts2_2);
    var posts1_1 = new Array("postID","postAuthor");
    var posts1_2 = new Array("postID","postAuthor");
    var posts2_1 = new Array("postID","postAuthor");
    var posts2_2 = new Array("postID","postAuthor");

    get it?
    Shawn

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Inside a relational design, there is no need to store tables inside tables.

    Your design should be

    usertable
    userID | ...

    table1
    ThreadID | userID |
    table2
    PostID | ThreadID | Message or whatever

    Which can then be joined to get the userdata or the post from a thread or user orwhatever.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #5
    Senior Coder
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    1,063
    Thanks
    2
    Thanked 0 Times in 0 Posts
    How would I create that thread-post relationship?
    Shawn

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by shlagish
    How would I create that thread-post relationship?
    SELECT table1.threadtitle, table1.threadstartdate, table2.posttitle, table2. threadpostdate FROM table1 INNER JOIN table2 ON table1.ThreadID = table2.ThreadID WHERE table1.ThreadID = xxx
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #7
    Senior Coder
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    1,063
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by raf
    SELECT table1.threadtitle, table1.threadstartdate, table2.posttitle, table2. threadpostdate FROM table1 INNER JOIN table2 ON table1.ThreadID = table2.ThreadID WHERE table1.ThreadID = xxx
    Not sure what all that means...

    I'm guessing that using table1.threadtitle means to take the row called threadtitle in table1.
    Am I right?

    I don't know what INNER JOIN does...
    nor what OR does...

    Could you explain it a little more ?
    Shawn

  • #8
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    table1.threadtitle means column 'threadtitle' from table 'table1'

    INNER JOIN means that you create a recordset using two tables, that you join, usualy by joining fields with equal values. That is the ON part.
    A random sql-tutorial http://www.w3schools.com/sql/sql_join.asp for more info
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #9
    Senior Coder
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    1,063
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks, I'll try to figure it out with that tutorial
    Shawn


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •