Page 1 of 1
How to retrive value by matching and also not matching
Posted: Mon Jul 30, 2007 8:19 am
by shivam0101
Hello,
i have two fields, f1 and f2
Code: Select all
SELECT * FROM table WHERE f1=96 OR f2=96
96 is the id. how do i get rest of the rest of the ids.
I can get their values and filter it out. But, i wanted it done in the query itself.
Thanx
Posted: Mon Jul 30, 2007 8:28 am
by superdezign
Your question isn't making sense. What are you after?
Posted: Mon Jul 30, 2007 9:34 am
by shivam0101
Clients belong to 2 type of categories, 1- seeker, 2-responder. when a person seeks his id will be entered in f1 and the person's id whom he wants to respond will be entered in f2. So 96 (example id) will be present as a seeker in some row and in responder in some rows. If i wanted to know whom all i have contacted (seeker or responder), how do i write the query?
Posted: Mon Jul 30, 2007 11:04 am
by onion2k
So, if I understand correctly, you want to search for all the rows with 96 in either f1 or f2, and return the
other id, eg f2 for rows where f1 = 96 or f1 for rows where f2 = 96?
Code: Select all
SELECT
IF (f1=96,f2,f1) as other_id
FROM `table`
WHERE f1 = 96 or f2 = 96
Posted: Tue Jul 31, 2007 7:04 am
by shivam0101
onion2k,
Thanx. Its working fine.