www.webdeveloper.com
Results 1 to 2 of 2

Thread: Select two values from same table in one record

  1. #1
    Join Date
    Jul 2007
    Posts
    245

    Select two values from same table in one record

    I've got this structure:

    Code:
    menu
    ------------
    option_id
    name
    
    
    options_order
    -------------
    option_id
    parent_id
    order

    "parent_id" specifies which submenu a menu item belongs to (which parent menu item it has). The value for top level menu items is 0.
    "order" specifies order within same submenu.

    I need to get a list with all the menu items, plus the name of its parent menu item ("top level" if parent_id = 0).

    I could have used just one table, but now it's too late. I'd rather keep it this way right now.

    How could I get what I want in a query?
    Last edited by Jazztronik; 07-22-2012 at 02:37 PM.

  2. #2
    Join Date
    Jul 2007
    Posts
    245
    Got it!

    This is what I did, just in case it helps someone else:

    Code:
    SELECT m1.name, m2.name as parent
    FROM menu m1
    INNER JOIN options_order o
    ON m1.option_id = o.option_id
    LEFT JOIN menu m2
    ON m2.option_id = o.parent_id

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles