SELECT QUERY - Multiple AND / OR ?

  • Hi,

    I'm having trouble with the following statement

    SELECT MemberID, UserName

    FROM tblUsers, tblProfile

    WHERE

    tblProfile.Education = 'Some College'

    OR tblProfile.Education = 'Associates Degree'

    AND tblProfile.MemberIDpr = tblUsers.MemberID

    ORDER BY MemberID DESC

    The 'OR' call generates tons of redundant records.

    Is there an easy way to do this?

    What should I use instead of OR ?

    Thanks in advance

    Rick

  • I am not sure what you are trying to accomplish but I think you want this:

    SELECT DISTINCT MemberID, UserName

    FROM tblUsers JOIN tblProfile on tblProfile.MemberIDpr = tblUsers.MemberID

    WHERE

    tblProfile.Education IN ('Some College', 'Associates Degree')

    ORDER BY MemberID DESC

    to help more I may need to know how the tables are linked I just assumed a bunch of things


    * Noel

  • Use brackets in your where clause.

    ...

    WHERE

    (

    tblProfile.Education = 'Some College'

    OR tblProfile.Education = 'Associates Degree'

    )

    AND tblProfile.MemberIDpr = tblUsers.MemberID

    ...


    Cheers,

    Kevin

  • Thanks Dogeth

    It worked great!

    quote:


    Use brackets in your where clause.

    ...

    WHERE

    (

    tblProfile.Education = 'Some College'

    OR tblProfile.Education = 'Associates Degree'

    )

    AND tblProfile.MemberIDpr = tblUsers.MemberID

    ...


  • Is there a specific reason for doing the join criteria in the where rather than in the join clause? Using the join is ANSI standard.

    Joe Johnson

    NETDIO,LLC.


    Joe Johnson
    NETDIO,LLC.

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

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