Results 1 to 10 of 10
  1. #1
    weston1980 is offline Novice
    Windows 10 Access 2003
    Join Date
    May 2018
    Posts
    3

    Question Please help - Need a query that filters results but shows differences in columns

    Hi,

    I am finding it hard to explain what I need so here is a simplified example of what I need to get from to:



    Original Table

    Make/Model Colour ID
    Ford Fiesta Red ANA SNS
    Ford Transit Green FND FBY
    VW Golf Blue CBC KJLS
    VW Beetle Red SDK LDD
    Ferrari F40 Green DLD WDV
    Ferrari F40 Blue LXD SLE
    Ford Transit Green DLSSDSD
    VW Golf Red 12323



    Queried Table (Result)
    Make/Model
    Red
    Green
    Blue
    Ford Fiesta
    ANA SNS
    DLSSDSD
    Ford Transit
    FND FBY
    VW Golf
    12323
    CBC KJLS
    VW Beetle
    SDK LDD
    Ferrari F40
    DLD WDV
    LXD SLE

  2. #2
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,422
    Try a cross tab query where Make is the row, Color is the column and ID is the value.
    However, I don't think you've specified the correct results for Transit and Fiesta.

    EDIT: never mind. I can see now that won't work as long as 2 or more makes have more than one record. No doubt a brighter mind will chime in before I get back.
    You may have to create a separate query for each color and combine them in to one query. If your data isn't really that simple I think you'd better 'fess up now.
    Last edited by Micron; 05-03-2018 at 12:01 PM. Reason: added info
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Weston,

    I am finding it hard to explain
    Try harder, if you can't describe what you are trying to do, do you really think someone else will be able to guess(correctly)??

    Pretend we are a bunch of 8 year olds who know nothing about database. Using simple, plain English try gain to tell us what you are trying to accomplish. No jargon.

    Good luck and welcome to the forum.
    Last edited by orange; 05-04-2018 at 06:08 AM.

  4. #4
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Micron
    I was surprised by your edit so decided to try it
    You're too clever for your own good - that's exactly the correct solution:

    Code:
    TRANSFORM First(Table1.[ID]) AS FirstOfID
    SELECT Table1.[MakeModel]
    FROM Table1
    GROUP BY Table1.[MakeModel]
    PIVOT Table1.[Colour];
    Result
    MakeModel Blue Green Red
    Ferrari F40 LXD SLE DLD WDV
    Ford Fiesta

    ANA SNS
    Ford Transit
    FND FBY
    VW Beetle

    SDK LDD
    VW Golf CBC KJLS
    12323

    NOTE:
    Replace Table1 with your table name
    You shouldn't use special characters like / in field names
    I've changed it to MakeModel but it would be better to have 2 separate fields for Make & Model

    Code:
    TRANSFORM First(Table2.[ID]) AS FirstOfID
    SELECT Table2.[Make], Table2.[Model]
    FROM Table2
    GROUP BY Table2.[Make], Table2.[Model]
    PIVOT Table2.[Colour];

    Make Model Blue Green Red
    Ferrari F40 LXD SLE DLD WDV
    Ford Fiesta

    ANA SNS
    Ford Transit
    FND FBY
    VW Beetle

    SDK LDD
    VW Golf CBC KJLS
    12323

    Both versions included in the attached
    Attached Files Attached Files
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  5. #5
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,422
    Your Ford Fiesta is missing a record, unless as noted, either the sample data given or the results desired are incorrect. The fact that there's multiple color values for a make means there's no aggregate function you can use that will work, and as you probably know, such a function is required for a Value column. Min and Max will provide different results, as would First and Last. That's why I also said the sample data better be realistic, otherwise all of the numeric aggregate functions can't be used with text. So we might as well know exactly what we're dealing with.
    Hey, is there a genius smilie?
    Last edited by Micron; 05-03-2018 at 12:39 PM. Reason: spelin and gramur

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    You're too clever for your own good - that's exactly the correct solution:
    Ah ha! Micron is clairvoyant, and adept with Access, SQL Transform/Pivot. And a really good guesser....Well done.

  7. #7
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    I am a dummy....
    There were two green transits .....
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  8. #8
    weston1980 is offline Novice
    Windows 10 Access 2003
    Join Date
    May 2018
    Posts
    3

    Thumbs up The Perfect Example

    Quote Originally Posted by ridders52 View Post
    Micron
    I was surprised by your edit so decided to try it
    You're too clever for your own good - that's exactly the correct solution:

    Code:
    TRANSFORM First(Table1.[ID]) AS FirstOfID
    SELECT Table1.[MakeModel]
    FROM Table1
    GROUP BY Table1.[MakeModel]
    PIVOT Table1.[Colour];
    Result
    MakeModel Blue Green Red
    Ferrari F40 LXD SLE DLD WDV
    Ford Fiesta

    ANA SNS
    Ford Transit
    FND FBY
    VW Beetle

    SDK LDD
    VW Golf CBC KJLS
    12323

    NOTE:
    Replace Table1 with your table name
    You shouldn't use special characters like / in field names
    I've changed it to MakeModel but it would be better to have 2 separate fields for Make & Model

    Code:
    TRANSFORM First(Table2.[ID]) AS FirstOfID
    SELECT Table2.[Make], Table2.[Model]
    FROM Table2
    GROUP BY Table2.[Make], Table2.[Model]
    PIVOT Table2.[Colour];

    Make Model Blue Green Red
    Ferrari F40 LXD SLE DLD WDV
    Ford Fiesta

    ANA SNS
    Ford Transit
    FND FBY
    VW Beetle

    SDK LDD
    VW Golf CBC KJLS
    12323

    Both versions included in the attached
    These are the perfect examples! Really can't thank you enough! - I have applied the logic to my database and it works perfectly!

    Thanks

    Dan

  9. #9
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Are you absolutely sure?
    As micron pointed out, if you do have two green ford transits or two of any other make/model with the same colour it will only list the first one.

    If that is your situation, you need a modified solution possibly involving two crosstabs with a union (NOT TESTED)
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  10. #10
    weston1980 is offline Novice
    Windows 10 Access 2003
    Join Date
    May 2018
    Posts
    3

    Smile

    Quote Originally Posted by ridders52 View Post
    Are you absolutely sure?
    As micron pointed out, if you do have two green ford transits or two of any other make/model with the same colour it will only list the first one.

    If that is your situation, you need a modified solution possibly involving two crosstabs with a union (NOT TESTED)
    Yeah this is fine - The example I gave to get my question across should not have had duplicates, as my database has no duplicates, I have a query to check this!

    Basically my issue was solved and not I have found CrossTab that I can use in future!

    Thanks Again

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

Similar Threads

  1. Query to show differences between tables
    By daveish in forum Queries
    Replies: 12
    Last Post: 01-20-2017, 07:49 AM
  2. Replies: 7
    Last Post: 07-28-2016, 03:12 PM
  3. Show Query Results in 3 Columns
    By WickidWe in forum Reports
    Replies: 6
    Last Post: 12-22-2013, 03:50 PM
  4. Replies: 3
    Last Post: 07-10-2011, 02:35 AM
  5. Replies: 12
    Last Post: 12-17-2010, 05:35 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