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 |
|
jmj
Starting Member
7 Posts |
Posted - 2002-07-17 : 11:01:57
|
| I have a query that pulls duplicate records from a table. I want to see all of the duplicates minus the students who have a flag set to yes on any of the duplicate records. How do I do this?My query still shows the student's name/info minus the records that the flag was set to yes So instead of getting this:TomTomJohn JohnI will get TomTomJohn JohnPaulHere's my query. Thanks, JSELECT s_LASTNAME, sFIRSTNAME, s.StudentID, s.STATUS, s.Flag FROM StudentDataDUMP sWHERE (Flag Is NULL OR Flag='') AND (((s.StudentID) In (SELECT [s.StudentID] FROM [StudentDataDump s] As Tmp GROUP BY [StudentID] HAVING Count(*)>1 ))) ORDER BY s.StudentID |
|
|
JustinBigelow
SQL Gigolo
1157 Posts |
Posted - 2002-07-17 : 11:29:38
|
| This should do it...select studentid, firstname, flagfrom studentswhere studentid in (select studentid from students where flag = '' group by studentid having count(*)>1)for testing...create table students ( studentid int, firstname varchar(20), flag char(1))insert into studentsvalues(1, 'John', '')insert into studentsvalues(2, 'Paul', '')insert into studentsvalues(3, 'Tom', '')insert into studentsvalues(1, 'John', '')insert into studentsvalues(2, 'Paul', 'y')insert into studentsvalues(7, 'Graz', '')insert into studentsvalues(3, 'Tom', '')hth,Justin |
 |
|
|
jmj
Starting Member
7 Posts |
Posted - 2002-07-17 : 11:46:56
|
| Thanks- worked like a charm. I knew it was something easy- which reminds me how much I still have to learn.j |
 |
|
|
|
|
|
|
|