Results 1 to 4 of 4
  1. #1
    EricRex is offline Advanced Beginner
    Windows 11 Access 2021
    Join Date
    May 2024
    Location
    Colorado
    Posts
    85

    How to Combine Two Separate Inner Join Queries into One

    Have been struggling to create a single Histogram query that generates Bucket Names and counts for two separate fields. The two following queries work fine separate, but can't be used in a Modern Chart that can only handle one query.



    Query1:
    Code:
    SELECT RHistogramBuckets.MaxValue AS Bucket, Count(StockTrades.cPosSizeR) AS PosSizeRTrades
    FROM StockTrades INNER JOIN RHistogramBuckets ON (StockTrades.cPosSizeR<[RHistogramBuckets].MaxValue) AND (StockTrades.cPosSizeR >= [RHistogramBuckets].MinValue)
    GROUP BY RHistogramBuckets.MaxValue, RHistogramBuckets.MinValue
    ORDER BY RHistogramBuckets.MinValue, RHistogramBuckets.MaxValue;
    Query2:
    Code:
    SELECT RHistogramBuckets.MaxValue AS Bucket, Count(StockTrades.cIStopR) AS PosSizeRTrades
    FROM StockTrades INNER JOIN RHistogramBuckets ON (StockTrades.cIStopR<[RHistogramBuckets].MaxValue) AND (StockTrades.cIStopR >= [RHistogramBuckets].MinValue)
    GROUP BY RHistogramBuckets.MaxValue, RHistogramBuckets.MinValue
    ORDER BY RHistogramBuckets.MinValue, RHistogramBuckets.MaxValue;
    I've tried bunch of different variations on those queries, but most generate syntax or expression errors.

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    Use a union query for separate rows or a third query to combine your two queries on one row- but would need something you can join on unless you want a Cartesian query

  3. #3
    EricRex is offline Advanced Beginner
    Windows 11 Access 2021
    Join Date
    May 2024
    Location
    Colorado
    Posts
    85
    Quote Originally Posted by CJ_London View Post
    Use a union query for separate rows or a third query to combine your two queries on one row- but would need something you can join on unless you want a Cartesian query
    Thanks, CJ! For a Modern Chart, Clustered Column, all of the data must be on the same row.

    Too bad I haven't been able to convince it to use my Bucket Labels, but it's good enough for now.

    Somewhat final versions of the queries and the combining query:

    Code:
    SELECT RHistogramBuckets.MaxValue, Count(StockTrades.cPosSizeR) AS PosSizeR
    FROM StockTrades INNER JOIN RHistogramBuckets ON (StockTrades.cPosSizeR<[RHistogramBuckets].MaxValue) AND (StockTrades.cPosSizeR >= [RHistogramBuckets].MinValue)
    GROUP BY RHistogramBuckets.MaxValue
    ORDER BY RHistogramBuckets.MaxValue;
    
    SELECT RHistogramBuckets.MaxValue, Count(StockTrades.cIStopR) AS IStopR
    FROM StockTrades INNER JOIN RHistogramBuckets ON (StockTrades.cIStopR<[RHistogramBuckets].MaxValue) AND (StockTrades.cIStopR >= [RHistogramBuckets].MinValue)
    GROUP BY RHistogramBuckets.MaxValue
    ORDER BY RHistogramBuckets.MaxValue;
    
    SELECT qrycPosSizeRHistogram.MaxValue, qrycPosSizeRHistogram.PosSizeR, qrycIStopRHistogram.IStopR
    FROM qrycPosSizeRHistogram INNER JOIN qrycIStopRHistogram ON qrycPosSizeRHistogram.MaxValue = qrycIStopRHistogram.MaxValue;

  4. #4
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    566
    Quote Originally Posted by EricRex View Post
    Thanks, CJ! For a Modern Chart, Clustered Column, all of the data must be on the same row.

    Too bad I haven't been able to convince it to use my Bucket Labels, but it's good enough for now.

    Somewhat final versions of the queries and the combining query:

    Code:
    SELECT RHistogramBuckets.MaxValue, Count(StockTrades.cPosSizeR) AS PosSizeR
    FROM StockTrades INNER JOIN RHistogramBuckets ON (StockTrades.cPosSizeR<[RHistogramBuckets].MaxValue) AND (StockTrades.cPosSizeR >= [RHistogramBuckets].MinValue)
    GROUP BY RHistogramBuckets.MaxValue
    ORDER BY RHistogramBuckets.MaxValue;
    
    SELECT RHistogramBuckets.MaxValue, Count(StockTrades.cIStopR) AS IStopR
    FROM StockTrades INNER JOIN RHistogramBuckets ON (StockTrades.cIStopR<[RHistogramBuckets].MaxValue) AND (StockTrades.cIStopR >= [RHistogramBuckets].MinValue)
    GROUP BY RHistogramBuckets.MaxValue
    ORDER BY RHistogramBuckets.MaxValue;
    
    SELECT qrycPosSizeRHistogram.MaxValue, qrycPosSizeRHistogram.PosSizeR, qrycIStopRHistogram.IStopR
    FROM qrycPosSizeRHistogram INNER JOIN qrycIStopRHistogram ON qrycPosSizeRHistogram.MaxValue = qrycIStopRHistogram.MaxValue;
    Not a whole lot to it. If you can't UNION stuff together (because thats the way the chart is), then you just join on as many matching columns as you need to, and rename stuff. no other way around it.

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

Similar Threads

  1. Replies: 4
    Last Post: 07-18-2022, 09:22 AM
  2. Combine multiple Inner Join same table
    By kaylachris in forum Queries
    Replies: 11
    Last Post: 03-12-2019, 05:37 AM
  3. Replies: 9
    Last Post: 01-23-2017, 08:53 AM
  4. Replies: 7
    Last Post: 06-19-2014, 12:00 PM
  5. Replies: 8
    Last Post: 05-31-2013, 05:20 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