Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    64
    Thanks
    0
    Thanked 1 Time in 1 Post

    MySQL Syntax and Priority

    I am not writing correct syntax so dont flame me about that... I simply do not know the syntax for this situation so instead i am writing the priority.

    SELECT * FROM table WHERE (condition1 AND contition2) OR (condition3 AND condition4)

    This is to relate two other tables and sometimes your id is in condition 1 and sometimes its in condition 3.... I want to prevent overlap between like IDs in the two tables...

    Is there a syntax to do that like above?
    No trees were harmed in the transmission of this message.
    However, a rather large number of electrons were temporarily
    inconvenienced.

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,633
    Thanks
    4
    Thanked 148 Times in 139 Posts
    your explanation really isn't clear. can you show your actual table layouts, sample data and the output you are trying to achieve? that might make what you are asking clearer.

  • #3
    New Coder
    Join Date
    Jan 2007
    Posts
    64
    Thanks
    0
    Thanked 1 Time in 1 Post
    Its is a relationship system between user & user, user & vendor, vendor & vendor



    users
    --------------
    ID
    NAME
    EMAIL
    etc.....

    vendors
    --------------
    ID
    NAME
    EMAIL
    etc...


    friends
    -----------
    USER_ID
    USER_TYPE
    FRIEND_ID
    RELATIONSHIP

    lets say i am a user and I wanted to find all instances of myself in the db

    I would need to look for myself
    WHERE USER_ID = MY ID AND USER_TYPE = MY TYPE
    but I would also need to see myself in the FRIEND_ID field WHERE RELATIONSHIP is MY_TYPE

    (In some cases you are someones friend, and in some cases someone is your friend, i want both)

    Make sense?

    Because you may have duplicate id's in the user & vendor table...

    So
    SELECT * FROM friends WHERE (USER_ID = ME AND USER_TYPE= MY TYPE) OR ( FRIEND_ID = ME AND RELATIONSHIP = MY TYPE )...

    Make sense?
    No trees were harmed in the transmission of this message.
    However, a rather large number of electrons were temporarily
    inconvenienced.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •