Jump to content

Recommended Posts

Hello all.

 

Is there someone that can help with searching a database that has Multiple Tables and fields.  I would like to search for the word %inspired% (say) in several tables and fields in the same database.  I know how to connect and how to create the method of passing the value to the query but what I don't know is how to assemble the SQL for the purpose of searching multiple tables and fields (redundant right).  Thanks for any help on the one.

 

 

Link to comment
https://forums.phpfreaks.com/topic/160975-search-query-multiple-tables/
Share on other sites

That's about the extent of the help I can give without more information, such as table and field names

 

The trouble is that there are about 50 tables and over 1000 fields that need searched.  I was hoping I would be able to use wild cards or something to search all tables and fields within the database.

Is there not a way to handle this operation?  I believe the DB is structured just fine.  The application that we've developed is extremely LARGE.  This is the my second time asking for help under this section and both times I've gotten "smart Alec" remarks. 

 

Is there a solution?  This time can it be constructive please.  Thanks.

Hi

 

Struggle to think of a reason to search that many fields for a particular value, and suspect that you might start hitting limits if you tried in one statement.

 

If you want to do it as one statement, then the crude way would be:-

 

"SELECT "TableName1", Id FROM TableName1 WHERE Field1 = '$Search' OR Field2 = '$Search'

UNION

SELECT "TableName2", Id FROM TableName2 WHERE Field1 = '$Search' OR Field2 = '$Search' OR Field3 = '$Search'

UNION

SELECT "TableName3", Id FROM TableName3 WHERE Field1 = '$Search'

UNION

SELECT "TableName4", Id FROM TableName4 WHERE Field1 = '$Search' OR Field2 = '$Search' OR Field3 = '$Search' OR Field4 = '$Search'"

 

But it would probably be better to loop through the tables, and in any case will be virtually unmaintainable.

 

All the best

 

Keith

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.