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

Conflict between Order By and Group By/Distinct

Hi all,

I am relatively new to Access, and have only made a few databases so far.

The one I am stuck on currently involves 2 tables via an ODBC link.

There is a unique field in both tables (ID) however it is giving me an error that the field is found in both tables. When looking at the data in the tables, there are duplicate IDs which I believe is causing the error.

I have attempted to remove the duplicates using DISTINCT which works, however it sorts from the oldest first.

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT Table1.ID
  2. FROM Table1
  3. ORDER BY Table1.ID DESC;
The problem is that it will only ever give me 12000 records at a time with the duplicates. If I sort these descending, I see the top half, if I sort them ascending, I see the bottom half. Because the above SQL code sorts after removing the duplicates, I always see the bottom half.

I believe I need to find a way of sorting descending first, and then using the DISTINCT or GROUP BY function after. I keep getting a syntax error when attempting this.

Any help would be greatly appreciated.

Regards,
Gareth
Feb 28 '11 #1
6 4876
orangeCat
83 64KB
Distinct does NOT remove anything. It really brings back only 1 records for the field involved.

If you want to count the duplicates/replicates you could

Expand|Select|Wrap|Line Numbers
  1. SELect count(possible dup field) from Table
If the field is intended to be the primary key, you appear to have some structure issues.
Feb 28 '11 #2
Thanks for the reply.

The DISTINCT is doing exactly what I need in the query except it is doing the bottom half of my table instead of the top. I believe this is because this is listed before the sort in the SQL as below.

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT Table1.ID
  2. FROM Table1
  3. ORDER BY Table1.ID DESC;
I believe I need to be able to sort descending, and then use DISTINCT, I may be wrong though.

Thanks
Gareth
Feb 28 '11 #3
Rabbit
12,516 Expert Mod 8TB
What do you mean top half and bottom half of the table? There's nothing in the query limiting the number of records being returned so it should return everything that is distinct.
Feb 28 '11 #4
For some reason I can only ever see 12000 records at any one time.

If I sort descending, I see rows 142000 down to 130000. If I sort ascending, I see rows 90000 to 102000

I can never see 142000 to 90000. Luckily however this is not a major problem as the top 12000 would be fine for me.

I have tried querying using different fields from the table, and it only returns 12000 records at any one time. When I use DISTINCT, it reduces this down to approx 1900 which is correct. Its just the bottom half of the table.
Feb 28 '11 #5
Thanks all for your help. I managed to solve this one by creating static tables from the ODBC link. Using Append and make table queries it is now working.
Apr 17 '11 #6
NeoPa
32,556 Expert Mod 16PB
Indeed Gareth. I suspect this issue is related to the ODBC link itself. It is certainly not standard behaviour (as you found when using it with your static table). The properties of your query could also have had a limit set, but that generally displays in the SQL seen as the TOP predicate (which was absent from your posted code so I doubt that's the case here). All things point to an issue with the specific ODBC link (which can come in all shapes and sizes of course).
Apr 18 '11 #7

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

Similar topics

4
by: kristofera | last post by:
I am trying to do a distinct grouping of some nodes sorted by a numeric value but for some reason the distinct (preceding-sibling filter) is applied to the result as if not sorted. If I don't use...
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
5
by: Mike Nolan | last post by:
I notice that 7.4 doesn't do default ordering on a 'group by', so you have to throw in an 'order by' clause to get the output in ascending group order. Is this something that most RDB's have...
6
by: John M | last post by:
Hi, The line below is used to feed a combobox. (It is from a database which is used to log pupil behaviour!) The 'incidents' table contains a list of students who have been involved in incidents....
3
by: orekinbck | last post by:
Hi There Our test database has duplicate data: COMPANYID COMPANYNAME 1 Grupple Group 2 Grupple Group 5 Grupple Group 3 Yada Inc 4 Yada...
10
by: OtisUsenet | last post by:
Hello, I am trying to select distinct dates and order them in the reverse chronological order. Although the column type is TIMESTAMP, in this case I want only YYYY, MM, and DD back. I am...
4
by: monomaniac21 | last post by:
hi! is it possible to do the aforementioned query - selecting only distinct in 1 col but retrieving all other cols at the same time. regards marc
2
by: igotyourdotnet | last post by:
I'm getting my dataset like this: SalesMan Sales Make Smith 25,000 1 Smith 9500 10 Smith 72,252 1 Smith 125,000 ...
6
by: Zuhaib Hyder | last post by:
SELECT TOP 5 tbltopic.subject, tbltopic.Topic_ID, tbltopic.forum_id FROM tblTopic, tblthread WHERE tbltopic.forum_id=32 and tbltopic.topic_id=tblthread.topic_id ORDER BY tblthread.message_date...
1
by: digidave | last post by:
I am keenly aware that my coding skills are extremely noob but please indulge me a second.. Take a look at these queries.. $sql = "SELECT DISTINCT year FROM _current_floats_config WHERE active =...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
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
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...

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.