473,394 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Opposite of "SELECT DISTINCT"

blyxx86
256 100+
Any idea how to run some SQL that would not Select distinct, but would select the values that are not distinct. Or something like "Select Duplicate"
Dec 7 '06 #1
12 17531
I think the keyword "COUNT" might be useful in this situation, though I forget the syntax...
Dec 7 '06 #2
http://www.petefreitag.com/item/169.cfm

That says it better than I can
Dec 7 '06 #3
NeoPa
32,556 Expert Mod 16PB
Blyxx86,

I'm afraid your question is not very clear.
If you can rephrase it in clear terms I'll let you have what you're looking for.

-Adrian.
Dec 8 '06 #4
blyxx86
256 100+
Blyxx86,

I'm afraid your question is not very clear.
If you can rephrase it in clear terms I'll let you have what you're looking for.

-Adrian.
Thank you. I'm trying to select from a table values that are not unique, therefore outputting only values that are duplicates.

I want to be able to compare entries, perhaps a SELECT DUPLICATE command or SELECT SIMILAR, except those are not actual commands.

I just can't figure out how to do it.
Dec 8 '06 #5
blyxx86
256 100+
Thank you. I'm trying to select from a table values that are not unique, therefore outputting only values that are duplicates.

I want to be able to compare entries, perhaps a SELECT DUPLICATE command or SELECT SIMILAR, except those are not actual commands.

I just can't figure out how to do it.
Or perhaps what I am trying to do is similar to this..

Table1 has one field called FirstName with the following entries:
Dave, Joe, Ted, Ted, Frank, Dave, Ted

When the SQL string is set up similar to my "SELECT DUPLICATE" the only values that are shown are:
Ted, Ted, Ted, Dave, Dave (Notice the missing Joe and Frank)

I need these duplicate entries within the table, but need to be able to see them clearly.
Dec 8 '06 #6
NeoPa
32,556 Expert Mod 16PB
Or perhaps what I am trying to do is similar to this..

Table1 has one field called FirstName with the following entries:
Dave, Joe, Ted, Ted, Frank, Dave, Ted

When the SQL string is set up similar to my "SELECT DUPLICATE" the only values that are shown are:
Ted, Ted, Ted, Dave, Dave (Notice the missing Joe and Frank)

I need these duplicate entries within the table, but need to be able to see them clearly.
Sorry Blyxx86.
I thought this thread had an answer :(. I'll look into it now.
It won't be a predicate but we can find some SQL to give the effect you require (might be a little more complicated to understand though).
Dec 8 '06 #7
blyxx86
256 100+
Sorry Blyxx86.
I thought this thread had an answer :(. I'll look into it now.
It won't be a predicate but we can find some SQL to give theeffect you require (might be a little more complicated to understand though).
I think I may have found an answer within this SQL bit...
Expand|Select|Wrap|Line Numbers
  1. SELECT email, 
  2.  COUNT(email) AS NumOccurrences
  3. FROM users
  4. GROUP BY email
  5. HAVING ( COUNT(email) > 1 )
  6.  
Expand|Select|Wrap|Line Numbers
  1. SELECT email
  2. FROM users
  3. GROUP BY email
  4. HAVING ( COUNT(email) = 1 )
  5.  
However, I believe that is straight SQL and will not work work within Access...

So the answer about COUNT was right, but I had no idea how to use that function.

This may help, but I do not know what the COUNT(column) AS NumOccurences reference even means. Well I could guess that it means Count as Number of Occurences, which is kinda what I want, but I want to show each occurence of the field.
Dec 9 '06 #8
NeoPa
32,556 Expert Mod 16PB
Please include the MetaData for all relevant datasets.
Posting Table/Dataset MetaData
Here is an example of how to post table MetaData :
Table Name=tblStudent
StudentID; Autonumber; PK
Family; String; FK
Name; String
University; String; FK
MaxMark; Numeric
MinMark; Numeric
Without that, I will try to illustrate how to do this generally.
Assume we are dealing with the table tblStudent shown above.
To produce a list of all student names which are not unique :
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM tblStudent INNER JOIN (SELECT [Name]
  3. FROM tblStudent
  4. GROUP BY [Name]
  5. HAVING Count([Name]) > 1) AS subDuplicates
  6.     ON tblStudent.Name = subDuplicates.Name
The subquery (defined within the () after INNER JOIN) will produce the actual list of names which are not unique, but will only display one instance of the name.
Dec 9 '06 #9
NeoPa
32,556 Expert Mod 16PB
I think I may have found an answer within this SQL bit...
Expand|Select|Wrap|Line Numbers
  1. SELECT email, 
  2.  COUNT(email) AS NumOccurrences
  3. FROM users
  4. GROUP BY email
  5. HAVING ( COUNT(email) > 1 )
  6.  
Expand|Select|Wrap|Line Numbers
  1. SELECT email
  2. FROM users
  3. GROUP BY email
  4. HAVING ( COUNT(email) = 1 )
  5.  
However, I believe that is straight SQL and will not work work within Access...

So the answer about COUNT was right, but I had no idea how to use that function.

This may help, but I do not know what the COUNT(column) AS NumOccurences reference even means. Well I could guess that it means Count as Number of Occurences, which is kinda what I want, but I want to show each occurence of the field.
When you have AS after something this means that the following text (name) will be considered the name of this item for future reference. In your case, NumOccurences will be the name that indicates COUNT(column).
You could also say something like
Expand|Select|Wrap|Line Numbers
  1. SELECT u.*
  2. FROM Users AS u
  3. ORDER BY u.Name
Every u. would be equivalent to Users..
Dec 9 '06 #10
missinglinq
3,532 Expert 2GB
In Access Help enter Find Duplicates Query Wizard. I think that's what you want, ready made!
Dec 9 '06 #11
blyxx86
256 100+
I modified the code just a bit to fit one of my tables.

Expand|Select|Wrap|Line Numbers
  1. SELECT QC.Serial, 
  2. Max(IIf([Overall]='Pass',[Date],Null)) AS [Pass Date], 
  3. Max(IIf([Overall]='Fail',[Date],Null)) AS [Fail Date]
  4. FROM QC
  5. GROUP BY QC.Serial
  6. HAVING ((Count(QC.Serial))>1);
  7.  
If I try to add another field to the SQL there, it gives me an error.
You tried to execute a query that does not include the specified expression 'Tech' as part of an aggregate function.
Expand|Select|Wrap|Line Numbers
  1. SELECT QC.Tech, 
  2. QC.Serial, 
  3. Max(IIf([Overall]='Pass',[Date],Null)) AS [Pass Date],
  4.  Max(IIf([Overall]='Fail',[Date],Null)) AS [Fail Date]
  5. FROM QC
  6. GROUP BY QC.Serial
  7. HAVING (((Count(QC.Serial))>1));
  8.  
I read up about how it isn't part of a TRANSFORM query, and how doing this would essentially create a cross-tab query.. The equation just gets more and more complex... I feel comfortable with VBA and Access one day, and the next it poses a new challenge. How... fun!
Dec 15 '06 #12
MMcCarthy
14,534 Expert Mod 8TB
I modified the code just a bit to fit one of my tables.

Expand|Select|Wrap|Line Numbers
  1. SELECT QC.Serial, 
  2. Max(IIf([Overall]='Pass',[Date],Null)) AS [Pass Date], 
  3. Max(IIf([Overall]='Fail',[Date],Null)) AS [Fail Date]
  4. FROM QC
  5. GROUP BY QC.Serial
  6. HAVING ((Count(QC.Serial))>1);
  7.  
If I try to add another field to the SQL there, it gives me an error.
You tried to execute a query that does not include the specified expression 'Tech' as part of an aggregate function.
Expand|Select|Wrap|Line Numbers
  1. SELECT QC.Tech, 
  2. QC.Serial, 
  3. Max(IIf([Overall]='Pass',[Date],Null)) AS [Pass Date],
  4.  Max(IIf([Overall]='Fail',[Date],Null)) AS [Fail Date]
  5. FROM QC
  6. GROUP BY QC.Serial
  7. HAVING (((Count(QC.Serial))>1));
  8.  
I read up about how it isn't part of a TRANSFORM query, and how doing this would essentially create a cross-tab query.. The equation just gets more and more complex... I feel comfortable with VBA and Access one day, and the next it poses a new challenge. How... fun!
If you add a field you will have to include it in the Group By

Expand|Select|Wrap|Line Numbers
  1. SELECT QC.Tech, QC.Serial, 
  2. Max(IIf([Overall]='Pass',[Date],Null)) AS [Pass Date],
  3.  Max(IIf([Overall]='Fail',[Date],Null)) AS [Fail Date]
  4. FROM QC
  5. GROUP BY QC.Tech, QC.Serial
  6. HAVING (((Count(QC.Serial))>1));
  7.  
Mary
Dec 15 '06 #13

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

Similar topics

3
by: Phil Powell | last post by:
Has anyone here ever done a case where you have a select multiple form element and you have to do both server-side and client-side validation? I am honestly not sure how to do it in Javascript (I...
4
by: Matt | last post by:
In ASP page, there is a "SELECT ALL" button, when user click it, it will select all checkboxes. I am not sure should I use client-side code to do that? the following is my approach but it didnt...
0
by: Steve | last post by:
Hi, Is there something fundamentally wrong with the following query? SELECT MAX(OrderID) AS Expr1 FROM Orders WHERE (MarketActionCode = 'S') AND (OrderLegCode = 'S') AND (Status = 'F') AND...
6
by: GSteven | last post by:
(as formerly posted to microsoft.public.access.forms with no result) I've created a continuous form which is based on a straightforward table (ex - customers - 100 records). On the form there is...
2
by: Dave Markle | last post by:
Good afternoon. I was just going through my code, analyzing it with FXCop, and FxCop gave me the following error on this code: MY CODE: Select Case termYears Case 5 : retVal.Append("1") Case...
0
by: ALaurie10 | last post by:
I am trying to write a "Select and From Statement but keep getting error 214727900 and my VBA points to the .Open Options:=acCmdTable. I am referencing a table in my Select. Can someone help me out....
11
by: bcurtu | last post by:
Hi, I have a BIIIIIG problem with the next query: cursor.execute(""" SELECT titem.object_id, titem.tag_id FROM tagging_taggeditem titem WHERE titem.object_id IN (%s) """,( eid_list))
41
bre1603
by: bre1603 | last post by:
I have a continuous form in Access 2007 called “Leadership Contact List.” It has a checkbox control for each record (bound to a field in the underlying table) that is used to email or create mailing...
0
by: Utku | last post by:
Is it possible to add "select all" and "select none" buttons to MultiChoiceDialog in wxPython?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.