...

View Full Version : MySQL Syntax and Priority



jayemvee
03-21-2007, 12:41 AM
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?

guelphdad
03-21-2007, 01:00 AM
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.

jayemvee
03-21-2007, 01:34 AM
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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum