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

  • SEARCH
  • Home
  • 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 7934013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:30:40+00:00 2026-06-03T21:30:40+00:00

I am trying to count distinct entries in 4 separate columns in a row

  • 0

I am trying to count distinct entries in 4 separate columns in a row and then total the results.

For instance the table headers look similar to this:

ID       Col1    Col2    Col3    Col4

Each column (save ID) can have a text value W, X, Y, or Z. Columns can have the same value.

What I am trying to do is figure a method for counting each entries in the columns, but only count W, X, Y, and Z once per row. So if:

ID       Col1    Col2    Col3    Col4
          X        X       Y
          Y        W       X
          Z        Y       Y

The result table would be:

    Value    Count
      W        1
      X        2
      Y        3
      Z        1

Any help would be greatly appreciated.

  • 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-06-03T21:30:41+00:00Added an answer on June 3, 2026 at 9:30 pm

    Perhaps I’m missing something, but would this be as simple as:

    Select Val, Count(*)
    From    (
            Select Id, Col1 As Val From Table1
            Union Select Id, Col2 From Table1
            Union Select Id, Col3 From Table1
            Union Select Id, Col4 From Table1
            ) As Z
    Where Z.Val Is Not Null
    Group BY Z.Val
    

    There is no reason to use Distinct and Union together as Union will make the results distinct. Because of that, we need to include the unique value for each row (Id).

    SQL Fiddle (This uses SQL Server but the same syntax will work in MS Access)

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

Sidebar

Related Questions

I'm trying to count how many distinct value of FLOOR there is but I
I'm trying to select distinct substring values of a field and count the number
I am trying to convert a SQL query to LINQ. Somehow my count(distinct(x)) logic
I'm trying to count the occurrences of a distinct set of cities and countries
I have a loginAudit table and I am trying to get a count for
I'm trying to get an average of a distinct count per day out of
I'm trying to count the number of rows with a distinct column with Active
I'm trying to get the count of each distinct field in my database. For
I'm trying to count the number of rows that have distinct values in both
I'm trying to do a distinct count inside my query and return the field,

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.