Go Back   Cloud Computing > Support > MySQL Issues.
 

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 06-01-11, 08:31
BOD Member
 
Join Date: Nov 2010
Posts: 91
Default 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?
Reply With Quote
  #2 (permalink)  
Old 06-01-11, 09:07
Rozanne's Avatar
BOD Member
 
Join Date: Nov 2010
Posts: 116
Default

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.
Reply With Quote
  #3 (permalink)  
Old 06-01-11, 09:11
BOD Member
 
Join Date: Nov 2010
Posts: 91
Default

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?
Reply With Quote
  #4 (permalink)  
Old 06-01-11, 09:16
Kristine Habeck's Avatar
BOD Member
 
Join Date: Nov 2010
Posts: 122
Default

I think you should use a single table, and study about indexing. That be helpful for you.
Reply With Quote
  #5 (permalink)  
Old 06-01-11, 09:19
BOD Member
 
Join Date: Nov 2010
Posts: 91
Default

@Kristine Habeck

Alright, I will check that part as well, but I am still worried about my large database.
Reply With Quote
  #6 (permalink)  
Old 06-01-11, 09:20
Rozanne's Avatar
BOD Member
 
Join Date: Nov 2010
Posts: 116
Default

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.
Reply With Quote
  #7 (permalink)  
Old 06-01-11, 09:22
BOD Member
 
Join Date: Nov 2010
Posts: 91
Default

But I think it will make queries slower than usual.
Reply With Quote
  #8 (permalink)  
Old 06-01-11, 09:23
Rozanne's Avatar
BOD Member
 
Join Date: Nov 2010
Posts: 116
Default

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.
Reply With Quote
  #9 (permalink)  
Old 06-01-11, 09:26
Kristine Habeck's Avatar
BOD Member
 
Join Date: Nov 2010
Posts: 122
Default

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.
Reply With Quote
  #10 (permalink)  
Old 06-01-11, 09:28
BOD Member
 
Join Date: Apr 2011
Posts: 85
Default

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.
Reply With Quote
  #11 (permalink)  
Old 06-01-11, 09:30
Rozanne's Avatar
BOD Member
 
Join Date: Nov 2010
Posts: 116
Default

No........OP just need to cope up 700,000 rows, so there is no need of partitioning.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump


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.