Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

SQL help - AND Operator

  • 21-02-2007 9:40am
    #1
    Registered Users, Registered Users 2 Posts: 872 ✭✭✭


    Hi,

    I have 2 tables featureAssignment and hotelAssignment. These tables have 2 columns in common: featureID and featuredetailID

    I need to select the hotelID column from hotelAssignment only when the featureID AND featuredetailID matches the featureID AND featuredetailID in the featureAssignment table.

    I seem to be having trouble with the AND operator. Here is what i have so far.

    SELECT ha.hotelID FROM hotelAssignment ha
    INNER JOIN featureAssignment fa
    ON(ha.featureID = fa.featureID AND ha.featuredetailID = fa.featuredetailID)

    It just seems to be ignoring the AND operator.

    Any ideas ? im going crazy trying to figure it out

    Thanks in advance


Comments

  • Registered Users, Registered Users 2 Posts: 4,792 ✭✭✭cython


    Not too familiar with the INNER JOIN operator myself, but I think the following piece of SQL should do similar to what you want:

    SELECT ha.hotelID FROM hotelAssignment ha, featureAssignment fa
    WHERE ha.featureID = fa.featureID
    AND ha.featuredetailID = fa.featuredetailID

    This is just me who doesn't like to overcomplicate things by the way, but I've seen this simplicity used in very large applications and queries

    From a cursory look, some DBMS's may not like the and statement inside the join. This is an example from the MySQL docs page:
    MySQL Docs wrote:
    This is an example of using a left to get lookup values from a table twice. The reason that an outer join was used instead of an inner join, was that in this case, there may be values that are null inside of the degree table.

    SELECT d.degDegId, m1.majDescription AS major_1, m2.majDescription AS major_2
    FROM degree AS d
    LEFT OUTER JOIN major AS m1
    ON d.degMajor1 = m1.majMajId
    LEFT OUTER JOIN major AS m2
    ON d.degMajor2 = m2.majMajId

    It looks like you may have to do a second join, with the joined table using a second identifier.

    Hope this is of some help


Advertisement