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.
Author |
Topic |
sridhar3004
Starting Member
34 Posts |
Posted - 2012-07-17 : 07:04:24
|
This is probably the most easiest of queries for many of you'll. but am stuck and hence need helpI've a customer master for whom I've 2 address types (shipping and billing) to be entered compulsorythere is a customer table and there is the address table with the customer id being the foreign keyI need a query which returns to me the customers for whom even 1 of the 2 address type is missing.Warm RegardsSridhar |
|
jleitao
Posting Yak Master
100 Posts |
Posted - 2012-07-17 : 07:58:15
|
can tou give an example? |
|
|
sridhar3004
Starting Member
34 Posts |
Posted - 2012-07-17 : 08:07:32
|
Customer Master table---------------------ID Name1 ABC2 EFGAddress Table-------------Line1 Line2 CustomerID AddressTypeblah blah 1 Shippingblah blah 1 Billinghdshf dfjsdf 2 ShippingI want the query to return customer 2 since 1 addresstype .i.e. billing is missing from the address table for 2 |
|
|
jleitao
Posting Yak Master
100 Posts |
Posted - 2012-07-17 : 08:10:52
|
give an example of wath you need in your output |
|
|
sridhar3004
Starting Member
34 Posts |
Posted - 2012-07-17 : 08:13:53
|
The output should return the customer idin this case 2CustomerID----------2 |
|
|
jleitao
Posting Yak Master
100 Posts |
Posted - 2012-07-17 : 09:29:08
|
SELECTcustomerID, COUNT(1) nr_recordsFROM adress_table A inner join customer_table CON a.CustomerID = C.IDgroup by customerIDhaving COUNT(1) < 2 |
|
|
sridhar3004
Starting Member
34 Posts |
Posted - 2012-07-17 : 09:41:59
|
Thank you very much for your quick response. It worked great. Again thank you. |
|
|
|
|
|