Search all collumns at once in a database

Just starting out? Need help? Post your questions and find answers here.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Search all collumns at once in a database

Post by Fangbeast »

If I type "Select * from myTablename where myField = '" + WhatToLookFor.s

So that selects all data from myTablename where myField = the data.

Is there a way to state in SQL where I can state something like "SELECT * FROM myTablename WHERE ANY field = '" + WhatToLookFor.s

Instead of having to type:

"Select * from myTablename where
myField = '" + WhatToLookFor.s + ' OR
myField1 = '" + WhatToLookFor.s + ' OR
myField1 = '" + WhatToLookFor.s + ' OR
myField1 = '" + WhatToLookFor.s"

etc, etc
stubbsi
User
User
Posts: 50
Joined: Tue Jul 04, 2006 8:59 pm
Location: Mt Martha, Australia

Post by stubbsi »

Nope. SQL requires that you specify the criteria against each column if that is what you want to search.

Is that a problem?

Based on the column names, you should be able to generate such an SQL statement by looking at the table layout, and therefore not require that you recode if you add columns.

If you want, i'll try and whack something together over the weekend.

depends on melbourne's weather though ...
Vincit qui primum gerit
"The Old Farts Wins" or "He Conquers Who First Grows Old"
User avatar
jqn
User
User
Posts: 97
Joined: Fri Oct 31, 2003 3:04 pm

Post by jqn »

Well, you can type
"Select * from myTablename where concat(myField, myField1, myField2, ...) like '%WhatToLookFor%' "
(or "... contains 'WhatToLookFor' ", if permited in database syntax)

Joaquin
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post by Fangbeast »

jqn wrote:Well, you can type
"Select * from myTablename where concat(myField, myField1, myField2, ...) like '%WhatToLookFor%' "
(or "... contains 'WhatToLookFor' ", if permited in database syntax)

Joaquin
jgn is "CONCAT( actually an sql keyword? I've never encounetered it before.

*EDIT* Never mind, I found it and wille xperiment. Thanks for the tip.

Edit. been testing this. Doesn't seem to work with sqlite. no results at all using the dll
Last edited by Fangbeast on Tue Oct 24, 2006 11:49 pm, edited 2 times in total.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post by Fangbeast »

stubbsi wrote:Nope. SQL requires that you specify the criteria against each column if that is what you want to search.

Is that a problem?

Based on the column names, you should be able to generate such an SQL statement by looking at the table layout, and therefore not require that you recode if you add columns.

If you want, i'll try and whack something together over the weekend.

depends on melbourne's weather though ...
Stubbsi, if I can work in Melbourne weather, then you can suffer with me damn it!!! My wife was just remarking tonight how frozen she was but I didn't feel it at all. We're up Boronia way at the foot of some hills.

Thanks for the offer but I have this one covered:):)
stubbsi
User
User
Posts: 50
Joined: Tue Jul 04, 2006 8:59 pm
Location: Mt Martha, Australia

Post by stubbsi »

at least I'm near the beach - mind you, the wind we get can shake the house to its foundations.

its less to do with how cold, but how nice it might be -- and also how much my wife wants me to do around the house, and if the kids ...

well -- you know.
Vincit qui primum gerit
"The Old Farts Wins" or "He Conquers Who First Grows Old"
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post by Fangbeast »

stubbsi wrote:at least I'm near the beach - mind you, the wind we get can shake the house to its foundations.

its less to do with how cold, but how nice it might be -- and also how much my wife wants me to do around the house, and if the kids ...

well -- you know.
Stubbsi, did't I tell you not to get married and have kids?? Damn, I forgot. And I forgot to follow my own advice. I have one who is 23 and for all the input she gives here, I may as well do everything myself!!

Anyone want a 23 year old who does bugger all???? I'm giving it away, no return policy.
stubbsi
User
User
Posts: 50
Joined: Tue Jul 04, 2006 8:59 pm
Location: Mt Martha, Australia

Post by stubbsi »

I have a 16 year old and a 13 year old.

Boys.

13 year old severe teenager, 16 year old still the old man a cuddle.
Vincit qui primum gerit
"The Old Farts Wins" or "He Conquers Who First Grows Old"
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post by Fangbeast »

Cuddle? What's that. I have to whinge mine into even thinking about it.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

@stibbsi and @jqn

Post by Fangbeast »

I found some help in an sqlite forum (yippee!!) to solve this problem.

Query.s = "SELECT * FROM addresses WHERE "
Query.s + "title||first||middle||last||street||suburb||city||postcode||state||country||work||home||mobile||"
Query.s + "company||misc1||misc2||email||note||category||displayas||firstentry||lastedit||deleted "
Query.s + "LIKE '%" + SearchText.s + "%' ORDER BY displayas"

will do field concatenation in sqlite (maybe even in other sql variants"
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

Fangbeast,

I think your best bet is to write a procedure that will generate the sql.

Concatng the strings together isn't a good idea, because it means you lose the benefits of any indexes.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post by Fangbeast »

GedB wrote:Fangbeast,

I think your best bet is to write a procedure that will generate the sql.

Concatng the strings together isn't a good idea, because it means you lose the benefits of any indexes.
GedB, that only works when you know what you are doing (ROFL), and I don't. There are no indexes in this database and may never need to be with any luck:):)
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Post Reply