Many to many relationships query don't work

  • Hi all and thx for your support, i have readTimothy Khouri's article - Understanding SQL: Many to Many Relationships.

    My database diagram is the following:

    The query is:

    SELECT Voyage.VoyageID, Voyage.SocieteID, Voyage.PAX, Voyage.PrixVente, Voyage.PrixAchat, Voyage.EtatAvancement, Voyage.EtatOption

    FROM Voyage INNER JOIN

    Voyages_Vols ON Voyage.VoyageID = Voyages_Vols.VoyageID INNER JOIN

    Vol ON Voyages_Vols.VolID = Vol.VolID

    WHERE (Voyage.VoyageID IN

    (SELECT VoyageID

    FROM Voyages_Vols

    WHERE (VolID = @VolID)))

    I have no result (the parameter value @VolID is correct).

    I want to retrieve all Voyages where VolID = @VolID (and later all Vols where VoyageID = @VoyageID).

    MSDN library for its tremendous knowledge, covering all aspects of programming.
    ASP.net for its articles, videos and forums about programming ASP.NET websites.
    SQLServerCentral.com forums where you get answers (and rights) in minutes and not hours!
  • HI There,

    Ok to get to the VolId I don't think you need to join all the way to the Vol table as you aren't returning or restricting any data from that table.

    try this:

    [font="Courier New"]

    SELECT        

       Voyage.VoyageID,

       Voyage.SocieteID,

       Voyage.PAX,

       Voyage.PrixVente,

       Voyage.PrixAchat,

       Voyage.EtatAvancement,

       Voyage.EtatOption

    FROM Voyage

       INNER JOIN Voyages_Vols

           ON Voyage.VoyageID = Voyages_Vols.VoyageID

    WHERE Voyages_Vols.VolID = @VolID[/font]

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • All is right. Thx for your reactivity and advise.

    MSDN library for its tremendous knowledge, covering all aspects of programming.
    ASP.net for its articles, videos and forums about programming ASP.NET websites.
    SQLServerCentral.com forums where you get answers (and rights) in minutes and not hours!

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

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