localtechguy Posted August 1, 2011 Share Posted August 1, 2011 Hello, I am trying to grab the results of two identical tables (in terms of format and fields etc..) from two different databases located on the same server/host. example TableA on DatabaseA: Select firstname, lastname From TableA WHERE date= $today results would be : John, Smith example2 TableA on DatabaseB : Select firstname, lastname From TableA WHERE date= $today results for this : Chuck, Norris I need a single select statement to give me the results : John, Smith Chuck, Norris Does anyone know how i can accomplish this? Thank you in advance for your help as I'v been struggling with this for awhile now and i can only seem to find documentation on JOINS which Im pretty sure is not what i need in this situation. Quote Link to comment https://forums.phpfreaks.com/topic/243513-select-results-from-2-tables-in-different-databases-on-same-server/ Share on other sites More sharing options...
Psycho Posted August 1, 2011 Share Posted August 1, 2011 Take a look at this link: http://www.dottedidesign.com/node/14 I have not read it entirely, but seems to be what you want to accomplish Quote Link to comment https://forums.phpfreaks.com/topic/243513-select-results-from-2-tables-in-different-databases-on-same-server/#findComment-1250395 Share on other sites More sharing options...
localtechguy Posted August 1, 2011 Author Share Posted August 1, 2011 Thanks for the quick reply! SELECT DatabaseA.TableA.firstname as firstnameA, DatabaseB.TableA.firstname as firstnameB, DatabaseA.TableA.lastname as lastnameA, DatabaseB.TableA.lastname as lastnameB FROM DatabaseA.TableA, DatabaseB.TableA WHERE DatabaseA.TableA.dateA = $today AND DatabaseB.TableA.dateA = $today; After taking a look at the link you relayed, it seems that the query they are suggesting would give me the results firsnameA firstnameB lastnameA lastnameB John Chuck Smith Norris I need the results to be appended not as new columns but at the end of the data set of one table using the same columns firstname lastname John Smith Chuck Norris It's looking like the only way to do this is maybe putting together a temporary table on the fly? Any advise? side note: as a further explanation of why i need the query to behave this way, is because i have a php script that dumps the result of a query into a .csv file (spreadsheet) so doing what was suggested above or doing a JOIN would give me the data, but it will spit it out to the spreadsheet by appending new columns as shown above instead of placing the data at the end of the data of the first table. ugh... im confusing myself. Quote Link to comment https://forums.phpfreaks.com/topic/243513-select-results-from-2-tables-in-different-databases-on-same-server/#findComment-1250401 Share on other sites More sharing options...
PFMaBiSmAd Posted August 1, 2011 Share Posted August 1, 2011 You would use a UNION query to get same structured results from more than one table. Quote Link to comment https://forums.phpfreaks.com/topic/243513-select-results-from-2-tables-in-different-databases-on-same-server/#findComment-1250441 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.