var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: help in writing a query
hi Friends ,
please help me out in creating a query...
Here is my condition...
use colldb(datbase 1)
select * from collection where collectionid(1,2,3,4,5,6,7,8)
use cardb (database 2)
select * from batch where batchid in(1,2,3,)
Here the collectionid and batchid are same.
The question is i want to get the ids 4,5,6,7,8 by comparing both the db and both the tables. please tell me how to write a query for this.
I want to restrict the ids that is not available in batchid which is available in collectionid.
please help me in this.
You should write your query like below:
select * from colldb(database 1)..collection
where collectionid in(1,2,3,4,5,6,7,8)
select * from cardb (database 2)..batch
where batchid in(1,2,3,)
just a few notes for madadi
- EXCEPT doesn't work in all versions of sql server
- the database names don't have parentheses
- the number of columns in the two tables are likely not the same, which would cause an error
i will try your idea....
i tried still its not working.... can any help me out.
Try this query.
select C.collectionid from [colldb].[dbo].[collection] C where
Not Exists(select 1 from [cardb].[dbo].[batch] B where A.CollectionID=B.BatchID)
the namespace is used before the table name. [Database Name].[Schema].[Table] to query table from two different database.