Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2010
    Posts
    5

    Unanswered: How to build mysql query for this?

    table1:dynamic_info
    catgory_id page_id title
    6 1 test
    table2:category
    category_id parent_id category_name
    1 0 travel
    6 1 car

    This is my table structure.

    Here What i need is.

    output:TRavel car test

    In table 2
    if parent id is 0 means it is category'
    if parentid is 1 means car is the subcategory of catgory travel..
    I cant build this one.. please help me

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT parent.category_name
         , child.category_name AS subcategory_name
         , dynamic_info.title
      FROM category AS parent
    INNER
      JOIN category AS child
        ON child.parent_id = parent.category_id
    INNER
      JOIN dynamic_info
        ON dynamic_info.catgory_id = child.category_id
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    Rudy - you should get a prize for simply being able to work out the question, it just looked like a random jumble of words to me

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    thanks mike
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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