 
|
|
 |
|  |
|
|
 |

06-01-11, 08:31
|
|
BOD Member
|
|
Join Date: Nov 2010
Posts: 91
|
|
How to join mysql tables with similar structure
Hi
I have multiple tables, tb_1, tb_2, tb_3. Each having the similar structure like id, title, content, and ratings. So as for now I am using following structure.
(Select*from tb_1 order by rating DESC) union (select*from tb_2 order by rating DESC) union (select*from tb_3 order by rating DESC) to list all titles from 1,2,3 tables, but the problem is, it only lists tables one after another. I want to list top ten rated titles from all the tables, so let me know how can I do that?
|

06-01-11, 09:07
|
 |
BOD Member
|
|
Join Date: Nov 2010
Posts: 116
|
|
Quote:
|
Select * From (Select* from tb_1 union all select* from tb_2 union all select* from tb_3) order by rating DESC limit 10
|
However, you need to re-think about your current table design, because lot of tables with the similar base name, but with a different incrementing suffix that all have the similar structure surly looks like an unskilled design.
|

06-01-11, 09:11
|
|
BOD Member
|
|
Join Date: Nov 2010
Posts: 91
|
|
Okay I will try to implement your recommendation. But currently I have more than 700,000 items arranged into various tables alphabetically. It might be too big to fill up all of them in a single table and I am concerned that query would be too slow, so what do you think about this problem?
|

06-01-11, 09:16
|
 |
BOD Member
|
|
Join Date: Nov 2010
Posts: 122
|
|
I think you should use a single table, and study about indexing. That be helpful for you.
|

06-01-11, 09:19
|
|
BOD Member
|
|
Join Date: Nov 2010
Posts: 91
|
|
@Kristine Habeck
Alright, I will check that part as well, but I am still worried about my large database.
|

06-01-11, 09:20
|
 |
BOD Member
|
|
Join Date: Nov 2010
Posts: 116
|
|
If you are database is not able to cope up 700,000 rows in a one table, then it's not desirable to called it as a database. FYI, mysql is able to handle a lot more than that.
|

06-01-11, 09:22
|
|
BOD Member
|
|
Join Date: Nov 2010
Posts: 91
|
|
But I think it will make queries slower than usual.
|

06-01-11, 09:23
|
 |
BOD Member
|
|
Join Date: Nov 2010
Posts: 116
|
|
If you do proper indexing, then it won't affect on query speed. The query we are talking about, including all the table will most probably even be faster. You shouldn't exist your database design, because you are thinking it could be slower. So make your design perfect, then run your queries. After this check the slow ones and try to set up them.
|

06-01-11, 09:26
|
 |
BOD Member
|
|
Join Date: Nov 2010
Posts: 122
|
|
If you cannot set up them for a particular query that meets your requirement, then you might think about switching to a good design to a crappy design. 
|

06-01-11, 09:28
|
|
BOD Member
|
|
Join Date: Apr 2011
Posts: 85
|
|
Which version of mysql you are using? If it's a 5.1, then you can use table partitioning with the indexes for even better performance. You should consider manual for more information.
|

06-01-11, 09:30
|
 |
BOD Member
|
|
Join Date: Nov 2010
Posts: 116
|
|
No........OP just need to cope up 700,000 rows, so there is no need of partitioning.
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -6. The time now is 00:51.
Powered by vBulletin® Version 3.6.4 Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0

Copyright © 1999-2012, BODHost Ltd. All rights reserved.
|