Results 1 to 11 of 11
  1. #1
    Jackroland is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2021
    Posts
    18

    [Challenge] Query with totals obscuring duplicates

    Hello everyone, I would like to offer you a "challenge", I have a database where I have a main table in which I have placed


    -ID
    -First name
    -Street
    -City
    -Image of the Persone


    I created a Query to then put as source data in a sub-form, but there is a problem.
    I wanted all the names present in New York +Image + the ID and the city itself to be displayed in the sub-form (I don't care about the street being displayed). But I have two people with the same name living in the same city, and therefore I get the same name twice. So I thought about putting a total in the query, the problem is that the total also involves the ID, and consequently it displays the same name twice. Explaining it with an example


    exist
    -Jhon with ID = 1 in New York at street x + mage.
    -Jhon with ID = 5 in New York at street y + Image.
    and in the subform I would like the same names not to be repeated. and so in this case I would like to display only a Jhon with ID and City.

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    Then I think you will have to leave the ID out of the query and set unique values to Yes. ID values (usually autonumbers) have no use to the user so there's not much point in displaying or using them.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Jackroland is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2021
    Posts
    18
    Quote Originally Posted by Micron View Post
    Quindi penso che dovrai lasciare l'ID fuori dalla query e impostare valori univoci su Sì. I valori ID (di solito i numeri automatici) non servono all'utente, quindi non ha molto senso visualizzarli o utilizzarli.


    I could also leave out the ID but not the image of the person, and this in the sub mask view makes me stay double Jhon even though I put a total in the query.

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Clearly there is a language issue due to translation but when you say 'sub mask' are you referring to a subquery or a subform?
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    Jackroland is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2021
    Posts
    18
    Quote Originally Posted by isladogs View Post
    Chiaramente c'è un problema di lingua dovuto alla traduzione, ma quando dici 'sottomaschera' ti riferisci a una sottoquery o a una sottomaschera?
    sorry, I mean subForm

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    Not much of that is making sense. If you have 2 Richards living in New York at 2 different addresses and you have 2 different images then they are 2 different people, so why would you want to show only one image and ID?? And which ID and image would you pick?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    Jackroland is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2021
    Posts
    18
    Quote Originally Posted by Micron View Post
    Non ha molto senso. Se hai 2 Richard che vivono a New York in 2 indirizzi diversi e hai 2 immagini diverse, allora sono 2 persone diverse, quindi perché dovresti mostrare solo un'immagine e un ID? E quale ID e immagine sceglieresti?
    i know it doesn't make much sense, but i'm interested in showing only one john that is accompanied by an image in case there are two two jhon displaying only one. I just wanted to know if it is technically possible to do this, so I put a challenge in the title

  8. #8
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    based on your requirement
    I would like to display only a Jhon with ID and City.
    have a rule as to which ID you want to use based on using one of first/last/min/max options for ID - something like

    Code:
    SELECT first(ID) as fID, Firstname, City
    FROM myTable
    GROUP BY Firstname, City
    but then you said

    but i'm interested in showing only one john that is accompanied by an image in case there are two two jhon displaying only one
    so for this you use a separate query to get the entire record

    Code:
    SELECT A.ID, A.Firstname, A.image, A.City
    FROM myTable A INNER JOIN (SELECT first(ID) AS FirstID FROM myTable GROUP BY firstname, city)  B ON A.ID=B.firstID

    I just wanted to know if it is technically possible to do this
    yes, very straightforward and the solution principle is a common requirement.

  9. #9
    Jackroland is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2021
    Posts
    18
    Quote Originally Posted by Ajax View Post
    based on your requirement

    have a rule as to which ID you want to use based on using one of first/last/min/max options for ID - something like

    Code:
    SELECT first(ID) as fID, Firstname, City
    FROM myTable
    GROUP BY Firstname, City
    but then you said



    so for this you use a separate query to get the entire record

    Code:
    SELECT A.ID, A.Firstname, A.image, A.City
    FROM myTable A INNER JOIN (SELECT first(ID) AS FirstID FROM myTable GROUP BY firstname, city)  B ON A.ID=B.firstID

    yes, very straightforward and the solution principle is a common requirement.
    I tried what you told me, but it keeps showing me 2 Jhon, I think the problem is the image, which doesn't make me group correctly to have only one Jhon. I leave you the code that I put below, tell me if I am wrong something.

    SELECT [Tab A].Firstname, [Tab A].Image, First([query 2].ID) AS FirstiID
    FROM [Tab A] INNER JOIN [query 2] ON [Tab A].ID= [query 2].ID
    GROUP BY [Tab A].Firstname;

    the street removed it from the final view.

  10. #10
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    tell me if I am wrong something.
    you are wrong, your sql is nothing like mine - and you haven't provided the sql to query2

    I think the problem is the image, which doesn't make me group correctly to have only one Jhon
    that is my second example - and there is no grouping on the image

  11. #11
    Jackroland is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2021
    Posts
    18
    Quote Originally Posted by Ajax View Post
    you are wrong, your sql is nothing like mine - and you haven't provided the sql to query2

    that is my second example - and there is no grouping on the image
    You're right, sorry if I didn't follow your code well, but I didn't understand it, now I understand it well and it works! in the end this just served me as an exercise to better understand some dynamics. Thanks Ajax

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 05-25-2019, 09:30 AM
  2. Query Calculation challenge
    By Perfac in forum Programming
    Replies: 6
    Last Post: 01-03-2019, 10:52 AM
  3. Query detail totals vs. Summary Totals do not match?
    By aellistechsupport in forum Queries
    Replies: 9
    Last Post: 01-15-2016, 11:36 AM
  4. SQL Query challenge in Microsoft Access 2013
    By Bingfoot in forum Queries
    Replies: 5
    Last Post: 10-07-2013, 07:58 AM
  5. Anyone fancy a challenge????!!!!!!
    By gregh in forum Database Design
    Replies: 1
    Last Post: 03-14-2011, 05:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums