query help

Discussion in 'Databases' started by dizyn, Sep 5, 2009.

  1. #1
    Hi,

    My database table structure is:

    PK_ID, category,parentId

    I wanted to select parentId, PK_ID, category where PK_ID=9 and then category and PK_ID where parentId = PK_ID

    Please help!

    Thanks.
     
    dizyn, Sep 5, 2009 IP
  2. davidbeckkam

    davidbeckkam Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    can any one tel me what is the problem of quiry
     
    davidbeckkam, Sep 5, 2009 IP
  3. BlazZ

    BlazZ Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Your structure looks a little bit wired to me perhaps i am just a little bit confused.

    you normally don't make any tables just for one id. how is the complete structure ?


    One example

    table_parent

    parentId|name|prename|categorie_id <- this is the foreign key
    table_categorie

    categorie_id|categorieName

    if you want to combine both data with each other you need an inner join.

    like this

    select * from table_parent inner join table_categorie on table_categorie.categorie_id = table_parent.categorie_Id where categorie_Id = 9;

    so without your complete structur i can't help you. But with this example it should be possible for you to solve the problem.
     
    Last edited: Sep 5, 2009
    BlazZ, Sep 5, 2009 IP
  4. adbroke999

    adbroke999 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi dizyn ,
    can you tell me which is primary key so i can give you appropriate suggestion for your query .
    One more if you are using Server 2005 so go to query builder and write query... You will definitely get the answer..
    :)
     
    adbroke999, Sep 14, 2009 IP
  5. HappyDaze

    HappyDaze Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    It sounds like you have the relationship around the wrong way. That table would be a "validation" table and you put it's ID field into a "joining" table that also has the ID from the parent table, then you can get the information you want. To summarize, you usually need the second ID field in a table that has the "many" relationship, not the "one" relationship, that's how the data sharing works.
     
    HappyDaze, Sep 16, 2009 IP