Results 1 to 2 of 2

Thread: help needed with a query

  1. #1
    Join Date
    Mar 2007
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help needed with a query

    hi i am facing a big problem with a mysql query

    i have 3 tables
    feat_proj
    pId,domain,projName,scope are the fields in this table

    value:

    1 dom proj_name xxxxx

    feat_mod
    mId,pId,modName
    1 1 mod1
    2 1 mod2

    feat_sec
    sId,mId,PId,secName
    1 1 1 sec1
    2 1 1 sec2
    3 2 1 sec3
    4 2 1 sec4

    i want a query which will display
    proj_name
    mod1
    sec1
    sec2
    mod2
    sec3
    sec4

    in a table. Any idea how to achieve this?

    thanks for the help,
    Suk

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    use a join query.


    Code:
    SELECT p.projName AS proj_name, m.mId AS mod, s.sId AS sec FROM feat_proj AS p LEFT JOIN feat_mod AS m ON m.pId=p.pId LEFT JOIN feat_sec AS s ON s.mId=m.mId GROUP BY p ASC ORDER BY mod ASC;
    The results of the query would be something like
    Code:
    proj_name mod sec
    project 1 1
    project 1 2
    project 2 3
    project 2 4
    provided that the details above. If you had multiple projects, it might return something similar to

    Code:
    proj_name mod sec
    project 1 1
    project 1 2
    project 2 3
    project 2 4
    project2 3 5
    project2 3 6
    project2 4 7
    project2 4 8
    http://dev.mysql.com/doc/refman/5.0/en/join.html reference, for more information

Bookmarks

Posting Permissions

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