473,466 Members | 1,538 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Retrieve Unique records from table whilst ignoring duplicates

45 New Member
I am trying to remove any duplicate value and display just the unique values using the select query below. I need the select query to display just the distinct values based on Member.ID

SELECT MEMBER.ACCT, MEMBER.NACD, MEMBER.FRST, MEMBER.ID, MEMBER.LAST, MEMBER.MID, ORDER.BAL, ORDER.TYPE, ORDER.TINUM
FROM MEMBER INNER JOIN ORDER ON MEMBER.ACCT = ORDER.SHACCT
WHERE (SELECT DISTINCT MEMBER.ID FROM MEMBER) AND ((ORDER.BAL)>0) AND ((ORDER.TINUM)=1);

NOTE: ID IS NOT A PRIMARY KEY BUT IT'S A UNIQUE NUMBER TO EACH RECORD
Mar 16 '10 #1
6 14981
code green
1,726 Recognized Expert Top Contributor
NOTE: ID IS NOT A PRIMARY KEY BUT IT'S A UNIQUE NUMBER TO EACH RECORD
I don't understand. How can the id be UNIQUE if there are duplicates?

But the principle of finding duplicates is
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM table WHERE id IN (
  2.    SELECT id FROM table GROUP BY id HAVING count(id >1)
Well this is one way
Mar 16 '10 #2
ck9663
2,878 Recognized Expert Specialist
You have two tables. Which one has duplicates and which one has the duplicate? I know ORDERS might have 1-N relationship with MEMBER. But it could also have actual duplicate records. That's why am asking.

~~ CK
Mar 16 '10 #3
toadmaster
45 New Member
In the member table I can pull up the following information

2345 THOMAS ADAMS 34687921
7321 HERMAN CORP 34687921
4323 JOE TORY TOM 34687921


34687921 is stored in the member table; I need a query to retrieve only one of the records with containing 34687921(which is the Member.ID row) it does not matter which one it retrieves
Mar 16 '10 #4
ck9663
2,878 Recognized Expert Specialist
Try this pseudo-code

Expand|Select|Wrap|Line Numbers
  1.  
  2. with dist_members (memberId)
  3. as
  4. (
  5. select distinct id from members
  6. )
  7. select memberid, o.columns...
  8. from dist_members m
  9. inner join orders o on m.memberd = i.id
  10.  
  11.  
Happy Coding!!!

~~ CK
Mar 16 '10 #5
nbiswas
149 New Member
Assuming you are using Sql server 2005+

The table information is as under

Expand|Select|Wrap|Line Numbers
  1. Id            Names                             DuplicateFields
  2. ------------------------------------------------------------------------------
  3. 2345     THOMAS ADAMS              34687921 
  4. 7321     HERMAN CORP                 34687921 
  5. 4323    JOE TORY TOM                 34687921
Query:
Expand|Select|Wrap|Line Numbers
  1. Select Id,Names,DuplicateFields From(
  2. Select Dense_Rank() Over(Partition by Duplicatefields Order by Id)x,Id,Names,DuplicateFields from tblInfo)y
  3. where y.x = 1
The output will be

Expand|Select|Wrap|Line Numbers
  1. Id            Names                             DuplicateFields
  2. ------------------------------------------------------------------------------
  3. 2345     THOMAS ADAMS              34687921 
Mar 25 '10 #6
holyzuou
13 New Member
WHERE (SELECT DISTINCT MEMBER.ID FROM MEMBER) AND ((ORDER.BAL)>0) AND ((ORDER.TINUM)=1);

what does that ,where is the "in" condition
Mar 25 '10 #7

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

Similar topics

9
by: paul | last post by:
Hiya everyone, I have two tables in SQL 2000. I would like to append the contents of TableA to TableB. Table A has around 1.1 Million Records. Table B has around 1 Million Reocords. ...
3
by: Beat Scheidiger | last post by:
I do not quite understand this property. Everything is seems clear to me, when I read the corresponding help text. But in practice I have a question: Why are there 3 identical records in the...
5
by: Terri | last post by:
I have a form with a multi-select combo. I dynamically build a SELECT statement, open a report, and set the recordsource to my dynamic SELECT statement. I count the records returned in the report...
1
by: Neil | last post by:
Hello everyone, I am making a program at the moment, and need HELP!!!. I'll start with the database, my field's r: fldSku - which a 6 digit number, no more no less (145682) fldDescription - which...
5
by: fruityfreak | last post by:
I would like to know how to I retrieve information from another database table... Instead of keying in manually, I would like to retrieve data directly from the logged in user row. For the user...
3
by: IsValidUN | last post by:
How do you select unique records? For example, if my data is like the following and I only want the repeated data (address information) to appear once for each theater_id. <xsl:for-each...
2
by: srusskinyon | last post by:
I need some help getting unique records from our database! I work for a small non-profit homeless shelter. We keep track of guest information as well as what services we have offered for...
2
by: bhargavi514 | last post by:
friends i need a php code to retrieve 10 records from database and display values in a table by using php and my sql
10
by: jmartmem | last post by:
Greetings, I have an ASP page with a 5x5 table embedded inside an Insert Record Form. This table contains several fields (mostly drop down list menus) and is used for corporate timekeeping (users...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.