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 2 of 2

Thread: Join two tables

  1. #1
    Regular Coder levani's Avatar
    Join Date
    Mar 2009
    Location
    Georgia
    Posts
    183
    Thanks
    29
    Thanked 1 Time in 1 Post

    Join two tables

    I have two tables that holds information about categories on my site. First table consists of two columns: ID and name, second table consists of three columns: id, category id and parent id. The second table describes the connections between categories in order to add sub categories in parent category.
    When I add new category one new record is added in both tables. If the category is main - 0 is recorded in the third column of the second table. If it isn't main category, the parent category id is recorded instead.

    So I want to retrieve all the main category ids (where parent id is 0) and than retrieve names from first table with these ids... Hope I'm clear...

    I'm afraid I'm not so familiar with mysql to handle with this problem myself. Can anyone please help?

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    I have two tables that holds information about categories on my site. First table consists of two columns: ID and name, second table consists of three columns: id, category id and parent id. The second table describes the connections between categories in order to add sub categories in parent category.
    Why do you need a second table for this? Can't you just add a parent_id column in the first table itself to indicate the relation? Take a look at a sample design at http://www.codeassembly.com/How-to-d...and-javascript
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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