Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Selecting and joining across multiple databases
Old 02-21-2008, 11:16 AM Selecting and joining across multiple databases
capetek's Avatar
Extreme Talker

Posts: 229
Location: Massachusetts
Trades: 0
I have a problem here.

I have 3 databases that sit ont he same server, I can access the databases seperatly find but what I need to do is access all 3 at the same time. All 3 databases have the same schema. Is it possible to do this? Here is my setup:

My 3 databases: wcmporg_db , alife_db and puritan_db

Here was my thought process on this but it doesnt work

PHP Code:
"SELECT * FROM puritan_db.main,wcmporg_db.main,alife_db.main  ORDER by main.burial_date desc  limit $offset,$limit
Any help would be appreciated
__________________
Anthony LeBoeuf
Cape-Tek IT Solutions

Please login or register to view this content. Registration is FREE

Great hosting at affordable pricing!
capetek is offline
Reply With Quote
View Public Profile Visit capetek's homepage!
 
 
Register now for full access!
Old 02-22-2008, 02:59 AM Re: Selecting and joining across multiple databases
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Wtf. Did you try to read mysql manual on joins? Also read about aliases. In your request you will have 3 tables with same names which is not allowed. You should say something like this:
Code:
select * 
from db1.main as m1
join db2.main as m2 on m1.id = m2.id
join db3.main as m3 on m1.id = m3.id
order by m1.field
You should clearly define how to join your tables. If you don't do that you will receive a table with number of columns = sum of number of columns in each table and with number of rows = number of rows in table1 * number of rows in table 2 * number of rows in table 3 which will most surely eat out all spare memory, go deeply into swap and put your server down.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 02-22-2008, 08:40 AM Re: Selecting and joining across multiple databases
Ultra Talker

Posts: 310
Trades: 0
What you're looking for is union here is how you do it :

Code:
 (SELECT field1, field2, field3 FROM db1.table1)
 UNION
 (SELECT field1, field2, field3 FROM db2.table1)
 UNION
 (SELECT field1, field2, field3 FROM db3.table1)
 order by field1 limit $offset, $limit;
further reading

Last edited by dman_2007; 02-22-2008 at 08:44 AM..
dman_2007 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Selecting and joining across multiple databases
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11979 seconds with 12 queries