Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 inner join table

Author  Topic 

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2012-04-24 : 03:49:36
i would like to know which of the following in table1 who has bought the code ABC.
but i get this error:Invalid object name table1

SELECT *
FROM openquery
( [testing] ,

'
select A.ID,FirstName,LastName
from
(select * from table1)A
inner join
(select ID
from table2 with (nolock)
where code in (''ABC'')
)B
on A.ID = B.ID
')

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-24 : 21:42:05
do you've table table1 present in server referred by testing?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2012-04-24 : 21:58:12
I'm accessing using table1 db.
Then I use the openquery which is testing to select the inner join on table2
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-24 : 22:24:20
is table1 a db?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2012-04-24 : 22:32:45
table1 is a table
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-24 : 22:40:57
then what do you mean by

I'm accessing using table1 db.


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2012-04-24 : 22:53:32
Oh I connect to the DB which can straight run select * from table1
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-25 : 00:34:58
so table2 is in [testing] ?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2012-04-25 : 02:21:41
Yes that is correct
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-25 : 14:39:33
then shouldnt it be this?


select A.ID,FirstName,LastName
from table1 A
inner join
(select * from openquery
( [testing] ,'select ID
from table2 with (nolock)
where code in (''ABC'')')
)B
on A.ID = B.ID


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -