By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,266 Members | 1,312 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,266 IT Pros & Developers. It's quick & easy.

How to find records that are present in one table not in another in sql server

P: 24
Hello ,

I have two tables that are Customer and Bill.

Customer table has the following fields


Bill table has the following fields


Now i am able to find the records who have paid the bill using the followin query.

select *from Bill,CustomerId where Bill.CustomerId=Customer.CustomerId

I am not able to find the records who have not paid the bill.... That is I have to fetch the records that are present in Customer table not in Bill table

Please any one send me the query for this...

Thank you
Feb 19 '10 #1
Share this Question
Share on Google+
5 Replies

Expert 100+
P: 1,754
Modify the below query as required.

SELECT <field_1>, <field_2>, <field_n> FROM TABLE <table_name>
WHERE <bill_flag_field> <> 'Paid'
Kindly refer to below attached link for more details;
SQL Tutorial
Feb 19 '10 #2

P: 24
Yes Mr.Sashi. I tried it out.It shows error... and I tried the '''where not exists'' query..It works.... Anyway thank you very much....
Feb 23 '10 #3

Expert 100+
P: 1,754
Thanks for sharing. Good luck :)
Feb 23 '10 #4

Expert 2.5K+
P: 2,878
Be careful with SQL's 3-Logic-Value.

Also, read this...

Happy Coding!!!

~~ CK
Feb 23 '10 #5

P: 4
--try this which are the customers are not billed between to days

select custid,custname from customer where custid not in(
select custid from bill where billdate between @fromdate and @todate)
Mar 11 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.