Gossamer Forum
Home : General : Databases and SQL :

Different fields, Same criteria

Quote Reply
Different fields, Same criteria
If I have 5 fields I'd like to search with the same criteria, is there any shorter way of doing that instead of

"Field1='a' OR Field2='a' OR Field3='a'....Fieldn='a'"

Additionally, I would like to have multiple criteria

"(Field1='a' OR Field2='a' OR Field3='a'....Fieldn='a') OR (Field1='b' OR Field2='b' OR Field3='b'...Fieldn='b')"

Thanks a lot, I'm hitting 64k limits like there's no tomorrow here! :)
Quote Reply
Re: [Wiggy] Different fields, Same criteria In reply to
Hello Wiggy,

YES there is a way.

But I am on Pluto right now and see a solution.

Where you are probably on Earth and don't see a solution.

Can you provide a brief example of what you wish to search for and what the fields might contain ?

Thanks

cornball
Quote Reply
Re: [Wiggy] Different fields, Same criteria In reply to
Untested, but what about;

Field1.Field2.Field3 = Value

Crazy

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [cornball] Different fields, Same criteria In reply to
how about something like this?

select * from table where concat(fielda, fieldb, fieldc) like "%value%"

you may also want to try indexing and using full text searches.

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [Wiggy] Different fields, Same criteria In reply to
Hello Wiggly,

Depending on what your end result required is :

This select finds 998,989,999 ......

SELECT n1,n2,n3 FROM table WHERE n1 in ('9','8') and n2 in ('9','8') and n3 in ('9','8')

Where as this select finds 129,783,299.....

SELECT n1,n2,n3 FROM table WHERE n1 in ('9','8') OR n2 in ('9','8') OR n3 in ('9','8')

So you can play with this to have multiple conditions for each field.

SELECT n1,n2,n3 FROM table WHERE n1 in ('9','8','7','6','5') and n2 in ('9','8')

Hope this helps

cornball