Assuming both databases are on the same instance of SQL Server.
Assuming the data is in Table1 and in Table2 and both tables are in the dbo
schema.
Assuming the Name field is a unique identifier so you won't have two people
named John Smith.
And assuming you have permission to access the databases and tables, then
try a query like:
SELECT DBa.Table1.dbo.Name, DBb.Table2.dbo.Name, Age, Sex
FROM DBa..dbo.Table1
JOIN DBb.dbo.Table2
ON DBa.dbo.Table1.Name = DBb.dbo.Table2.Name
I have intentionally included the Name column from both tables to emphasis
that you could use either one.
Since it is possible to have two people with the same name, I suggest adding
an additional column to uniquely identify each person. Maybe PersonID. Then
the ON clause would be ON DBa.dbo.Table1.PersonID= DBb.dbo.Table2.PersonID
If you really meant that you had two tables (instead of two databases), then
you wanted:
SELECT DBa.Name, DBb.Name, Age, Sex
FROM DBa
JOIN DBb
ON DBa.Name = DBb.Name
--
Rick Byham, MSFT
(Implies no warranty or rights)
"Lousada" <carloslousada (AT) gmail (DOT) com> wrote
Quote:
Hello! I have 2 databases (DBa and DBb),
dba Name,Age and dba Name,Sex i want to join to get name,age
and sex?
how do i get this data?
|