473,405 Members | 2,445 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,405 software developers and data experts.

Using Distinct in a column

I would like to pull unique records of a SINGLE column but not the other related columns. When I use DISTINCT, it pulls up all the records which are unique across the columns. Here is the code....
Expand|Select|Wrap|Line Numbers
  1. SELECT distinct columnA,columnB,columnC
  2.  
  3. FROM Table
  4.  
  5. ORDER by columnA,columnB,columnC;
What I would like to see, is Distinct records from column A, and not from other columns. But I would like to have the records from other columns to show up when I pull distict records from column A.

If I change the sql statement to -
Expand|Select|Wrap|Line Numbers
  1. SELECT distinct columnA
  2.  
  3. FROM Table
  4.  
  5. ORDER by ColumnA,columnB,columnC;
Get the following error...

ORDERBY clause (columnB,ColumnC)conflicts with Distinct.

Can some one help me, please?

Regards,

Omnitha
Aug 19 '08 #1
4 3689
Krandor
50
I tried it on my database. If you have something in the ORDER BY, it has to be in the select also. You can't have a SELECT Distinct on one column and then ORDER BY with multiple columns.

Either add the other columns to the select (I think that would be better) or get rid of them from the ORDER BY.
Aug 19 '08 #2
NeoPa
32,556 Expert Mod 16PB
This will be difficult. Mainly because it makes no sense.

How can it make sense to show three columns in a query where only one of them is covered by the DISTINCT qualifier?

Consider what you would expect to be displayed where the following data were encountered :
Expand|Select|Wrap|Line Numbers
  1. ColumnA  ColumnB  ColumnC
  2.   A        B         C
  3.   A        B         D
  4.   A        E         F
Can you see why that is nonsensical?
Aug 20 '08 #3
Appreciate your answer. That makes more sense...now I understand the limitations of Distinct function.
Aug 22 '08 #4
NeoPa
32,556 Expert Mod 16PB
I'm glad if I helped you to understand.

Understanding is always preferable to simple solutions.

In situation like this, you may want to consider GROUPing by rather than DISTINCT. You would have a similar problem, but at least you'd have the option of aggregating fields not GROUPed BY (Aggregate functions include Sum(); First(); Last(); Min(); Max(); etc).

Hope this helps with you problem.
Aug 23 '08 #5

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

Similar topics

5
by: Martin Feuersteiner | last post by:
Dear Group I'm having trouble with the clause below. I would like to select only records with a distinct TransactionDate but somehow it still lists duplicates. I need to select the...
0
by: sallybonbons | last post by:
I have tried looking this up and couldn't find a straightforward answer: I just want to find DISTINCT records on one column, but pick the most recent one (a date in another column). table: ...
4
by: Johnson, Shaunn | last post by:
Howdy: Can someone tell what the difference (and why you would use it) is between the following: select distinct on (col_1, col_2), col_1, col_2, col_3
1
by: Alex Satrapa | last post by:
I have a table from which I'm trying to extract certain information. For historical reasons, we archive every action on a particular thing ('thing' is identified, funnily enough, by 'id'). So the...
17
by: keith | last post by:
I am trying to get a exact count of different distinct entries in an Access column. At first, I was trying to work with three columns, but I've narrowed it down to one to simplify it. I've searched...
2
by: Frank van Vugt | last post by:
Hi, Not exactly a showstopper, but I noticed this behaviour: db=# create table f1 (id int, value int); CREATE TABLE db=# insert into f1 select 1 as id, null; INSERT 25456306 1
6
by: issac | last post by:
Hi folks Im trying to do a simple query involving the distinct keyword and an access 2000 db, but have been frittering with it for amost and hour and a half and I cant make it work. This is...
4
by: burgensteen | last post by:
Hi all, New to this forum, so to start 'A big hello to you all'. My question: I have a drop down menu that is created from the username in my database but is distinct: ...
1
newnewbie
by: newnewbie | last post by:
Desperately need help in creating a query to count unique values in a table. I am a Business analyst with limited knowledge of Access….My boss got me ODBC connection to the underlying tables for our...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
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...

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.