944,175 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 13834
  • MySQL RSS
Aug 19th, 2005
0

MySQL Multiple Table Search

Expand Post »
I have a MySQL database design which consists of several tables that are identical in structure, but contain different sets of data (each table is assigned to a specific group of people). This is because each table might grow to several tens of thousands entries, and with a prospect of up to a hundred (or more) groups, I wanted to keep things small for each group.

There is a SINGLE case where I'd need to perform a search on an index field accross ALL tables. JOINS haven't worked, and the only thing I've managed to get to work was a UNION. But a UNION accross a hundred tables, i.e.
MySQL Syntax (Toggle Plain Text)
  1. (SELECT * FROM a WHERE id=1) UNION
  2. (SELECT * FROM b WHERE id=1) UNION
  3. (SELECT * FROM c WHERE id=1) UNION ... etc
will get VERY expensive, VERY soon. The syntax
MySQL Syntax (Toggle Plain Text)
  1. SELECT * FROM a,b,c WHERE id=1
obviously doesn't work because the field id is not unique, and if I change the syntax to
MySQL Syntax (Toggle Plain Text)
  1. SELECT * FROM a,b,c WHERE a.id=1 OR b.id=1 OR c.id=1
then the result I get is not what I was looking for (the results are joined).

Does anybody know a better way of searching accross multiple identical tables on a single field?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jaguarcy is offline Offline
1 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: Creating New Columns From Calucations
Next Thread in MySQL Forum Timeline: some help in importing and exporting data





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC