Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Union ALL tables...possible with wildcard?

Status
Not open for further replies.

Shrum

Programmer
May 17, 2002
122
US
I have a content manager that I wrote and I was looking into a simple solution for a feature I am thinking of...

All the tables in the database that my system uses are the same structurally so I want to UNION them all together to do *site searches*.

Is it possible to indicate *via a SQL statement* a UNION of all tables in a database without actually specifying them all individually?



=============================
Sean Shrum
Shrum Consulting
C.A.T.S.: Consulting: Programming: R/C Soaring:
 
Surely you might just as well do a series of simple selects and build up the data in your programming language. Presumably you have PERL, PHP or ASP managing this process. I can't see you'd gain much in getting MySQL to do it.

 
The issue is that I create a LOT of tables...each directory gets it's own table. Granted, yes, I thouhgt about having my content manager *build* the select statement but it seemed like there should be a way to UNION all the table together if need be...then again, the general thinking might be "Why not just use 1 table"....I just might have to do that instead.

Oh well...

Thanx for the help

=============================
Sean Shrum
Shrum Consulting
C.A.T.S.: Consulting: Programming: R/C Soaring:
 
I suggest two reasons why there is no short-cut Union.

1) 99.999% of databases have tables which to some degree are not union compatible. Thus you would have to have some potentially complex method of specifying which ones to include.

2) You may have different selection criteria on some or all of the tables - again introducing complexity into the SQL syntax to do this.

So what I'm saying is writing it in eg PHP would be no more difficult than in any theoretical version of SQL.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top