Help need structuring a query

  • I need some help structuring q query. In my database, I have two tables:

    • Entity: columns are EntityID and Name
    • Entity_MTM: columns are EntityID1, EntityID2, and Description

    I am building a web interface to facilitate entering the many-to-many relationships. To get to this page, the user will have done something that defines one of the entities, call it EntityBaseID. One of the things I want to show on the page are all relationships that have been defined for EntityBaseID by showing the Name of all existing MTM relationships. The problem is that EntityBaseID can appear as either EntityID1 or EntityID2 in Entity_MTM.

    If I knew that EntityBaseID only appeared as EntityID1, a simple query such as:

    SELECT Name FROM Entity, Entity_MTM WHERE Entity_MTM.EntityID1=EntityBaseID AND Entity. EntityID=Entity_MTM.EntityID2

    would suffice. But since I want to check both Entity_MTM.EntityID1 and Entity_MTM.EntityID2, I am not sure what to do. Please help.

  • Okay - I figured it out. I just needed an OR in the WHERE clause...

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

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