Results 1 to 2 of 2

Thread: get values from database

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2004

    get values from database


    I have a table which is called product the attributes as following

    product_id product_name

    1 ABC
    2 CDE
    3 TEST

    I have another table is called subproduct
    because proudct_id 2 and 3 are the subproducts of product_id 1
    the structure of this table as following

    id product_id sub_id

    1 1 2
    2 1 3

    I have a question about the query, how could I return the result as following:

    SID product_name sub_name
    1 ABC CDE
    2 ABC TEST

    P.S product_id and sub_id are come from same attribute(product_id -product table)


    id product_name sub_name

  2. #2
    Addicted Member
    Join Date
    Sep 2004
    SID product_name sub_name
    1 ABC CDE
    2 ABC TEST
    I'm not a true expert in SQL, but it seems to me you have a problem right there. You want to output product_name and sub_name, but the source columns for both of those are the exact same column - product.product_name. There may indeed be a way to write this query in SQL that I can't think of, but right now it looks like you have a data model problem.

Posting Permissions

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

Click Here to Expand Forum to Full Width