| Author |
Topic |
|
taylan
Starting Member
5 Posts |
Posted - 2011-01-20 : 08:56:15
|
| hi@all,my question is a very easy one i thinki have one query, which should be executed over several databasesstatus:use aselect * from tablewhere id=1use bselect * from tablewhere id=1what i want is, should be something like that use a, b // i know it doesnt work :-)select * from tablewhere id=1thanksciao |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-01-20 : 09:03:32
|
| Select ColumnName1,...ColumnNameNFrom DatabaseName.Dbo.TableName AInner Join DatabaseName2.Dbo.TableName2 B on A.ColumnName=B.ColumnNameIf there are matching columns in both database's table you can join them and can use them in above way to get the desired result. |
 |
|
|
taylan
Starting Member
5 Posts |
Posted - 2011-01-20 : 09:19:21
|
| hi, thanks for your quick answer but i think that was not what i meanti have two databases, they both have a table (with the same structure + same columns etc.)the query will just make a select but from two databases, different resultsi already have my "join"s but it has nothing to do with my problemthanks |
 |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-01-20 : 09:29:24
|
| well then provide us some more details .. e.g. table name, some data of both tables, your query and the required output Perhaps we can then help you out! |
 |
|
|
taylan
Starting Member
5 Posts |
Posted - 2011-01-20 : 09:42:21
|
| okimagine you have for each country over the world one database.now i want to have with one query from all databases (countries) the people how are older than 50for one country it would like this (with two queries)use germanyselect name, age from peoplewhere age>50use austriaselect name, age from peoplewhere age>50now i want just one query which can provide both results?? |
 |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-01-20 : 09:57:56
|
| you can construct a query with unions e.g. Select Name,Age From Germany.Dbo.people where age>50Union AllSelect Name,Age From Austria.Dbo.people where age>50Union All... |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-01-20 : 10:26:40
|
| Run thisselect 'select * from '+name+'..table where id=1' from sysdatabasesCopy the result and run itMadhivananFailing to plan is Planning to fail |
 |
|
|
taylan
Starting Member
5 Posts |
Posted - 2011-01-20 : 10:28:56
|
| yes, that works, thanks a lot.. my query is still too long but anyway it works :-)thanks especially for your quick answers.. i will recommend this site to otherstake care |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-01-20 : 10:31:52
|
quote: Originally posted by taylan yes, that works, thanks a lot.. my query is still too long but anyway it works :-)thanks especially for your quick answers.. i will recommend this site to otherstake care
You are welcome MadhivananFailing to plan is Planning to fail |
 |
|
|
|