Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 196651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:47:08+00:00 2026-05-11T16:47:08+00:00

in Access DB … I need to extract the itemcode / desc combination for

  • 0

in Access DB…
I need to extract the itemcode / desc combination for each itemcode in the following table where the desc has been used most frequently.

most frequently could possibly mean that there was only one version (see added record for pear)

in the case of itemcode 777, I’ll have to decide later which description version to use. if there are multiple records, each containing a single version of a description, that will definately create an additional problem.

the original question should probably also include returning the first row for itemcodes like 777 where all the existing records for an itemcode contain a single, unique description (so that the count would always be 1). the first row may not always be the correct version – but I won’t be able to automate that phase anyway.

---------------------
itemcode  | desc
---------------------
123       | apple
123       | apple
123       | apple
123       | apple 2
123       | apple-2
001       | orange
001       | orange
001       | ORANGE 1
001       | orange-1
666       | pear
777       | bananananana
777       | banana

so – I’m looking to end up with the following:

---------------------
itemcode  | desc
---------------------
123       | apple
001       | orange
666       | pear
777       | bananananana

I think I’m close, but the following only gets the description in the database which appears most frequently and only returns one row.

SELECT itemcode, desc, count(desc)
from table
group by itemcode, desc
having count(desc) = 
(
 select max(ct) from 
 (
  select itemcode, desc, count(desc) as ct
  from table
  group by itemcode, desc
  )
);

returns:

---------------------
itemcode  | desc
---------------------
123       | apple
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:47:08+00:00Added an answer on May 11, 2026 at 4:47 pm

    This would work through a correlated sub-query:

    SELECT 
      t.itemcode, t.desc, Count(t.desc) AS CountOfdesc
    FROM 
      [table] AS t
    GROUP BY 
      t.itemcode, t.desc
    HAVING 
      Count(t.desc) IN (
        SELECT TOP 1 
          Count(i.desc)
        FROM 
          [table] AS i
        WHERE 
          i.itemcode = t.itemcode
        GROUP BY 
          i.itemcode, i.desc
        ORDER BY 
          Count(i.desc) DESC
      )
      AND t.desc = (
        SELECT TOP 1 
          i.desc
        FROM 
          [table] AS i
        WHERE 
          i.itemcode = t.itemcode
        GROUP BY 
          i.itemcode, i.desc
        ORDER BY 
          i.desc
      )
    ;
    

    Returns (tested with Access 2003):

    itemcode  desc          CountOfdesc
    001       orange        2
    123       apple         3
    666       pear          1
    777       banana        1
    

    BTW you should really not be calling a table “table” and a column “desc”. Those are reserved SQL keywords, just avoid them to make your life easier.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 95k
  • Answers 95k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would like to see your full LINQ query (including… May 11, 2026 at 7:04 pm
  • Editorial Team
    Editorial Team added an answer If you want O(n) time and no extra memory usage… May 11, 2026 at 7:04 pm
  • Editorial Team
    Editorial Team added an answer The feature you are looking for as been disabled for… May 11, 2026 at 7:04 pm

Related Questions

I have been trying to read a picture saved in Access DB as a
I have a requirement to create a simple database in Access to collect some
I need to insert new records into an Access database. I'm using Visual Studio
How can I determine if a user, in say Access, is a member of
I have two databases, one is an MS Access file, the other is a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.