• Status: Solved
  • Priority: Medium
  • Security: Private
  • Views: 25
  • Last Modified:

Show SQL duplicated result

Dear expert

I got question about duplicating the query, now when I select query like code below the sql automaticly remove the duplicated result, the deal here is I want SQL to show duplicated result... how to do that?
SELECT [Membership]
      ,[Membershipid] ,[firstnamn]
      ,[lastnamn]
  FROM [company].[db].[Member]
  Where membershipID in ('392102','392371', '394240', '394240', '394910', '394910', '395173'
, '395173', '395173', '395189', '395189', '395189', '395782','396232', '396232', '396232', '396509', '396509', '396509'
,'398145', '398166' ,'399037' , '399230', '401361', '401361'
,'401361', '401361', '411750', '411856' , '412141' , '412141'
,'414297' , '414297','414770','414770','415043','415043','415288','416131','416251','416251','416251','416917','417459',
'417906','417906','417906','418765','418905','418905','419177','419177','419228','419228','419348','419417','419887',
'419947','419991','420063','420063','420108','420319','420319','420319','420763','420963','421685','421685','421685',
'421882','421882','422296','422296','422508','422508','422856','422856','423003','423180','423255','424130','424130',
'424148','424148','424820','425036','425036','425495','425495','425495','425495','425495','425495','425495','425495',
'425495','425495','425495','425495','425495','425495','425495','425495','425495','425495','425495','425495','425495',
'425495','425861','426021','426082','426083','426089','449926','449926') 

Open in new window

0
WeTi
Asked:
WeTi
  • 5
  • 3
1 Solution
 
Geert GOracle dbaCommented:
there is probably no duplicate in the result, you are assuming this wrongly
if a row matches a criteria, it matches,
it won't return the same row more if it matches the criteria multiple times

if you have duplicates in your data, then they will show

if you have duplicates in your search criteria, then those are ignored
you have duplicates in your search criteria

how did you build that search criteria ?
you need to look there for duplicates

insert your search criteria into a separate table
and then check that separate table with a group by

select medlemsnr, count(*) 
from separate_table
group by medlemsnr 
having count(*) > 1

Open in new window

0
 
WeTiAuthor Commented:
Compare with a excel, in excel there are duplicated lines with other info, I just need to export this query to copy the result in it, I thought... However the query auto remove all the duplicated ids... I cannot mark all and copy...
0
 
WeTiAuthor Commented:
Sorry, I forgot to edit the search criteria. now its correct.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
WeTiAuthor Commented:
You said:
if you have duplicates in your search criteria, then those are ignored
you have duplicates in your search criteria

Yes I need sql to show those duplicates in my search criteria... not ignore them.
0
 
Geert GOracle dbaCommented:
then insert them into a separate table
with a join you can have duplicates

how do you mean now it is correct ?
your search criteria has still got duplicates

that's 3 of these :
'395173', '395173', '395173'
0
 
WeTiAuthor Commented:
Yes that is my question, I want sql to show those duplicate...
0
 
Geert GOracle dbaCommented:
you can't with an in clause

insert those numbers into a new separate table
and then join with that separate table

create table #crit (membershipID int);

insert into #crit (membershipId) values (392102);
insert into #crit (membershipId) values (392371);
... etc 

SELECT m.[Membership]
      ,m.[Membershipid] ,m.[firstnamn]
      ,m.[lastnamn]
  FROM [company].[db].[Member] m, #crit c 
  Where m.membershipID = c.membershipID;

Open in new window


that'll give you the duplicates
0
 
WeTiAuthor Commented:
Great solution! Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now