many to many relations

  • I have one table and the columns are bookingreference,complaintreference,category1,category2,desriptionofthecomplaint,

    one bookingref have one complaintid,

    one complaintid have many bookingreferences,

    one complaintid have many categories and one category have many complaintid,

    one complaintid have many category2 and one category 2 have many complaints.

    I need to prepare the data into tables and load them to prepare reports on it.

    can anyone suggest me the best approach.

    Thanks pavan

  • lak.konduri (10/21/2012)


    I have one table and the columns are bookingreference,complaintreference,category1,category2,desriptionofthecomplaint,

    one bookingref have one complaintid,

    one complaintid have many bookingreferences,

    one complaintid have many categories and one category have many complaintid,

    one complaintid have many category2 and one category 2 have many complaints.

    I need to prepare the data into tables and load them to prepare reports on it.

    can anyone suggest me the best approach.

    Thanks pavan

    Depending on what the reporting requirements actually are, it would seem that LEFT OUTER JOINing all of the other tables to the BookingRef table on the ComplaintID would do the trick. This doesn't actually look like a many-to-many problem because of that.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • It might be easier for Jeff, or anyone else to give you a more detailed answer if you would illustrate what one or two of your reports look like. Depending on the data you want, a JOIN, a LEFT JOIN, or even a CROSS APPLY of a subquery might be appropriate ways to tie data together from multiple tables.

    __________________________________________________

    Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
    Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills

  • lak.konduri (10/21/2012)


    I have one table and the columns are bookingreference,complaintreference,category1,category2,desriptionofthecomplaint,

    one bookingref have one complaintid,

    one complaintid have many bookingreferences,

    one complaintid have many categories and one category have many complaintid,

    one complaintid have many category2 and one category 2 have many complaints.

    I need to prepare the data into tables and load them to prepare reports on it.

    can anyone suggest me the best approach.

    Thanks pavan

    I don't even see a complaintid in your table.

    I do think you will need multiple tables (more than 2), but the rest is so sketchy I couldn't say what they were at this point.

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply