Solved

where field B is duplicated and field K is not null (SQL)

Posted on 2008-10-24
7
303 Views
Last Modified: 2012-05-05
I don't even know if this is possible in SQL.
Some records have a duplicate value in Column B (2 records).  One of the records will also have a value in Column K.  I don't want to see these records.

It this possible?
0
Comment
Question by:NO_CARRIER
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 22797112
better post sample data and identify which records you don't want to see.
0
 
LVL 1

Author Comment

by:NO_CARRIER
ID: 22797257
attached is some sample data.
as you'll notice the second field (Account) is the same for the last two records.  However only the second last record has a comment of "PRIMARY PIN SAME AS SPOUSE PIN".  This record I don't want to see.

Note that another record also has "PRIMARY PIN SAME AS SPOUSE PIN" as a comment, but the ACCOUNT is not duplicated, therefore I would still like to see this record.
Company	Account	ID	PIN	Received	First Name	Last Name	Status	Joint PIN	Spouse Name	Spouse PIN	Comment
HAL	PH399PBL	1P8P93U	9911UU98P	I	xxx	yyy	A	9928U9335	xxx yyy		
HAL	PJ1157AL	1P8PU19	9U298995U	I	xxx	yyy	A	9U8911UU5	xxx yyy		
HAL	PJ5528AL	1P89198	11UU7U359	I	xxx	yyy	A		xxx yyy	11UU7U359	PRIMARY PIN SAME AS SPOUSE PIN
HAL	PJ1532AL	1P8P915	115789P7U	I	xxx	yyy	L	1127U5193	xxx yyy		
HAL	PJ1533AL	1P8P915	115789P7U	I	xxx	yyy	L	1127U5193	xxx yyy		
HAL	PJ159UAL	1P8P97P	11U3829P9	I	xxx	yyy	A		xxx yyy	1215P5U71	
HAL	PJ1739AL	1P81P81	9P89U2181	I	xxx	yyy	A	93755P259	xxx yyy		
HAL	PJ18U2AL	1P81187	9379P9311	I	xxx	yyy	L		xxx yyy	9379P9311	PRIMARY PIN SAME AS SPOUSE PIN
HAL	PJ18U2AL	1P81187	9379P9311	I	xxx	yyy	L		xxx yyy	92U231932	

Open in new window

0
 
LVL 1

Author Comment

by:NO_CARRIER
ID: 22797280
If you paste the above sample in Excel as TEXT it will delimit properly into each column.
0
Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 22797384

select *
from tableX
where [Account ID] not in(select [Account ID] from TableX as A where tableX.[Spouse PIN] <>null)
0
 
LVL 1

Author Comment

by:NO_CARRIER
ID: 22797675
for some reason that always returns no records.
if I use In instead of Not In (without checking Column K), I get all the records as expected.  If the subquery is just  Not In (select [Account ID] from temp as A) .. it still doesn't return anything.

0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 22797705
post the sql of the query you are using
0
 
LVL 22

Accepted Solution

by:
Flyster earned 500 total points
ID: 22798305
Here's a round-about way, but it seems to work. Make the following queries:

SELECT YourTable.Account, Count(YourTable.Account) AS AccountCount
FROM YourTable
GROUP BY YourTable.Account;

SELECT YourTable.Company, YourTable.Account, YourTable.ID, YourTable.[First Name], YourTable.PIN, YourTable.Received, YourTable.[Joint PIN], YourTable.[Last Name], YourTable.Status, YourTable.Comment, YourTable.[Spouse Name], YourTable.[Spouse PIN], CountAccounts.AccountCount, IIf([AccountCount]>1 And Len([Comment])>1,"Yes","No") AS Filter
FROM YourTable INNER JOIN CountAccounts ON YourTable.Account = CountAccounts.Account
WHERE (((IIf([AccountCount]>1 And Len([Comment])>1,"Yes","No"))="No"));

I used the Len function in the filter criteria as is null and "" didn't seem to work. I tested it on your data and it returned 8 records.

Flyster
0

Featured Post

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question