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
 blank

Author  Topic 

Christech82
Starting Member

20 Posts

Posted - 2013-04-10 : 14:42:47
blank

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-04-10 : 15:11:39
You could query like shown below:
select * from HOUSE h
where not exists
(
select * from RENT_AGREEMENT r
where r.HOUSE_NO = h.HOUSE_NUM
);
Go to Top of Page

Christech82
Starting Member

20 Posts

Posted - 2013-04-10 : 15:23:49
quote:
Originally posted by James K

You could query like shown below:
select * from HOUSE h
where not exists
(
select * from RENT_AGREEMENT r
where r.HOUSE_NO = h.HOUSE_NUM
);





It is worked Thank you much for your help James
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-04-11 : 02:22:26
you can also achieve it using LEFT JOIN or NOT IN

select * from HOUSE h
where h.HOUSE_NUM not in
(
select r.HOUSE_NO from RENT_AGREEMENT r
)

select h.* from HOUSE h
LEFT JOIN RENT_AGREEMENT r
ON r.HOUSE_NO = h.HOUSE_NUM
WHERE r.HOUSE_NO IS NULL


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-15 : 00:17:51
Hi Christech82,

Don't delete your content after getting solution.. These posts will help others who have this type of problems
Go to Top of Page
   

- Advertisement -