Re: [PHP] need help for a where clause
If you are using MySQL you may want to look at the CASE statement in the "Control flow functions for use with SELECT Statements" it would look like SELECT CASE A.Afn WHEN 1 THEN B.Bfn1 WHEN 2 THEN B.Bfn2 WHEN 3 THEN B.Bfn3 FROM A,B IN MySQL Hope That Helps.. Phil "Alex Shi" <[EMAIL PROTECTED]> schrieb im Newsbeitrag [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Thanks! This is what I need! > > Alex Shi > > > > "Sascha Cunz" <[EMAIL PROTECTED]> ?? > :[EMAIL PROTECTED] > A solution on that depends strongly on how much values A.Afn would take. For > 3, it's still okay. But i wouldn't do more. > > Against what shall the B.Bfn* be checked? What Data do you want to be > returned > from the query? > > try: > > SELECT ### FROM A, B WHERE > ((A.Afn=1) AND (B.Bfn1 = ...)) OR > ((A.Afn=2) AND (B.Bfn2 = ...)) OR > ((A.Afn=3) AND (B.Bfn3 = ...)) > > where you should replace ### with things you want to select and ... with the > things you want to check. > > On more than 3 different values for A.Afn, you should use a more normalized > version of B. > > i.e.: B contains only one Bfn field and a Reference to A.Afn. > -> SELECT ### FROM A, B WHERE B.AfnRef = A.Afn AND B.Bfn = ... > > Sascha > > Am Montag, 7. Oktober 2002 00:33 schrieb Alex Shi: > > Hi, > > > > I need a where clause in following situation: > > > > Say I want to query two tables: A and B. In table A there is field > > Afn, while in table B there are 3 fields: Bfn1, Bfn2 and Bfn3. I want > > to do a query, in which the where clause must do these things: > > > > if A.Afn=1, then check value of B.Bfn1; > > if A.Afn=2, then check value of B.Bfn2; > > if A.Afn=3, then check value of B.Bfn3. > > > > So how can I create such a where clause to do this? > > Thanks in advance! > > > > Alex Shi > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] need help for a where clause
Thanks! This is what I need! Alex Shi "Sascha Cunz" <[EMAIL PROTECTED]> 写入消息新闻 :[EMAIL PROTECTED] A solution on that depends strongly on how much values A.Afn would take. For 3, it's still okay. But i wouldn't do more. Against what shall the B.Bfn* be checked? What Data do you want to be returned from the query? try: SELECT ### FROM A, B WHERE ((A.Afn=1) AND (B.Bfn1 = ...)) OR ((A.Afn=2) AND (B.Bfn2 = ...)) OR ((A.Afn=3) AND (B.Bfn3 = ...)) where you should replace ### with things you want to select and ... with the things you want to check. On more than 3 different values for A.Afn, you should use a more normalized version of B. i.e.: B contains only one Bfn field and a Reference to A.Afn. -> SELECT ### FROM A, B WHERE B.AfnRef = A.Afn AND B.Bfn = ... Sascha Am Montag, 7. Oktober 2002 00:33 schrieb Alex Shi: > Hi, > > I need a where clause in following situation: > > Say I want to query two tables: A and B. In table A there is field > Afn, while in table B there are 3 fields: Bfn1, Bfn2 and Bfn3. I want > to do a query, in which the where clause must do these things: > > if A.Afn=1, then check value of B.Bfn1; > if A.Afn=2, then check value of B.Bfn2; > if A.Afn=3, then check value of B.Bfn3. > > So how can I create such a where clause to do this? > Thanks in advance! > > Alex Shi -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] need help for a where clause
A solution on that depends strongly on how much values A.Afn would take. For 3, it's still okay. But i wouldn't do more. Against what shall the B.Bfn* be checked? What Data do you want to be returned from the query? try: SELECT ### FROM A, B WHERE ((A.Afn=1) AND (B.Bfn1 = ...)) OR ((A.Afn=2) AND (B.Bfn2 = ...)) OR ((A.Afn=3) AND (B.Bfn3 = ...)) where you should replace ### with things you want to select and ... with the things you want to check. On more than 3 different values for A.Afn, you should use a more normalized version of B. i.e.: B contains only one Bfn field and a Reference to A.Afn. -> SELECT ### FROM A, B WHERE B.AfnRef = A.Afn AND B.Bfn = ... Sascha Am Montag, 7. Oktober 2002 00:33 schrieb Alex Shi: > Hi, > > I need a where clause in following situation: > > Say I want to query two tables: A and B. In table A there is field > Afn, while in table B there are 3 fields: Bfn1, Bfn2 and Bfn3. I want > to do a query, in which the where clause must do these things: > > if A.Afn=1, then check value of B.Bfn1; > if A.Afn=2, then check value of B.Bfn2; > if A.Afn=3, then check value of B.Bfn3. > > So how can I create such a where clause to do this? > Thanks in advance! > > Alex Shi -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] need help for a where clause
> I need a where clause in following situation: > > Say I want to query two tables: A and B. In table A there is field > Afn, while in table B there are 3 fields: Bfn1, Bfn2 and > Bfn3. I want > to do a query, in which the where clause must do these things: > > if A.Afn=1, then check value of B.Bfn1; > if A.Afn=2, then check value of B.Bfn2; > if A.Afn=3, then check value of B.Bfn3. > > So how can I create such a where clause to do this? I suspect you'd be better off asking this question in a mailing list for whatever database you are using. At the very least, it would probably help to mention the database but it's still not real relevant here in this (already high volume) mailing list. CYA, Dave -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php