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 8220339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:29:21+00:00 2026-06-07T13:29:21+00:00

I am trying to write an Access query that joins a single table twice,

  • 0

I am trying to write an Access query that joins a single table twice, then run a count on one field from each.

SELECT Wines.wID, 
       Wines.num, 
       Wines.Brand, 
       Wines.wYear, 
       Wines.Variety, 
       Wines.Score, 
       g.fName, 
       g.lName , 
       Count(DISTINCT Votes.vote1) AS Vote1,  
       Count(DISTINCT Votes_1.vote2) AS Vote2
FROM   ((Wines 
           LEFT JOIN Guests AS g 
              ON Wines.wID = g.wineID) 
           LEFT JOIN Votes 
              ON Wines.num = Votes.vote1) 
           LEFT JOIN Votes AS Votes_1 
              ON Wines.num = Votes_1.vote2
WHERE (((Wines.pID)=2))
GROUP BY Wines.wID, Wines.num, Wines.Brand, 
         Wines.wYear, Wines.Variety, Wines.Score, g.fName, g.lName
ORDER BY Wines.Score DESC , Count(DISTINCT Votes.vote1) DESC;

However, it does not work. COUNT(DISTINCT) does not seem to work in Access. Leaving it out allows the query to run, but I do not get the correct results. Using it just once works fine. I can’t seem to write a subquery in the COUNT statement and I’m not really sure what else to do.

  • 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-07T13:29:23+00:00Added an answer on June 7, 2026 at 1:29 pm

    You can use DCount, if you are working within MS Access, a subquery, or it may be possible to set up a count query and join to that. I am not sure where the duplication is coming from, so the notes below illustrate a few ideas. It is not properly tested.

    SELECT Wines.wID, 
       Wines.num, 
       Wines.Brand, 
       Wines.wYear, 
       Wines.Variety, 
       Wines.Score, 
       g.fName, 
       g.lName , 
       DCount("vote1","votes","vote1"=Wines.num) AS Vote1,  
       (SELECT Count(Vote2) FROM 
          (SELECT DISTINCT vote2 
           FROM votes v
           INNER JOIN Wines w ON v.vote2=w.Num
           WHERE w.pID=2 AND w.num=Wines.num)) AS Vote2
    FROM   Wines 
               LEFT JOIN Guests AS g 
                  ON Wines.wID = g.wineID
    
    WHERE (((Wines.pID)=2))
    GROUP BY Wines.wID, Wines.num, Wines.Brand, 
             Wines.wYear, Wines.Variety, Wines.Score, g.fName, g.lName
    ORDER BY Wines.Score DESC , vote1 DESC;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a query that extracts and transforms data from a table
I have trying to write a query in Access 2010. I have a table:
I am trying to write a VBA scriptin Microsoft Access that will interface with
I'm trying to write a subroutine in access 2003 that removes all quote characters
I am trying to get record from my table in Access against the value
I am working on an Access database. I am trying to write a query
I am trying to write a plsql query that allows me to query a
I am trying to write some vba code in Excel to query a table
I'm trying to write a query in Oracle SQL to access a particular substring
I am trying to check if I have write access to a specific key

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.