PC Review


Reply
Thread Tools Rate Thread

Combining Queries

 
 
carl
Guest
Posts: n/a
 
      26th Apr 2011
I use these 2 queries...

SELECT BTA_Trades.FirmId, Sum(BTA_Trades.TradeVolume) AS MM_NonPIP
FROM BTA_Trades
WHERE BTA_Trades.AccountType='MarketMaker' And
BTA_Trades.TradeType<>'Pip'
GROUP BY BTA_Trades.FirmId;

SELECT BTA_Trades.CounterpartFirmId, Sum(BTA_Trades.TradeVolume) AS
PA_OUT
FROM BTA_Trades
WHERE (((BTA_Trades.AccountNumber)='PA-OUT'))
GROUP BY BTA_Trades.CounterpartFirmId;

Is there a way to combine the queries so I don;t have to run each of
them ?

Thank You in Advance.
 
Reply With Quote
 
 
 
 
Bob Barrows
Guest
Posts: n/a
 
      26th Apr 2011
carl wrote:
> I use these 2 queries...
>
> SELECT BTA_Trades.FirmId, Sum(BTA_Trades.TradeVolume) AS MM_NonPIP
> FROM BTA_Trades
> WHERE BTA_Trades.AccountType='MarketMaker' And
> BTA_Trades.TradeType<>'Pip'
> GROUP BY BTA_Trades.FirmId;
>
> SELECT BTA_Trades.CounterpartFirmId, Sum(BTA_Trades.TradeVolume) AS
> PA_OUT
> FROM BTA_Trades
> WHERE (((BTA_Trades.AccountNumber)='PA-OUT'))
> GROUP BY BTA_Trades.CounterpartFirmId;
>
> Is there a way to combine the queries so I don;t have to run each of
> them ?
>
> Thank You in Advance.


"Combine"? This word can be interpreted in several different way. What do
you want the resulting query to return? A little more information please.
Show us a couple rows of sample data returned from each query, then show us
what you want the "combined" results to look like.


 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      26th Apr 2011
On Tue, 26 Apr 2011 11:16:55 -0700 (PDT), carl <(E-Mail Removed)> wrote:

>I use these 2 queries...
>
>SELECT BTA_Trades.FirmId, Sum(BTA_Trades.TradeVolume) AS MM_NonPIP
>FROM BTA_Trades
>WHERE BTA_Trades.AccountType='MarketMaker' And
>BTA_Trades.TradeType<>'Pip'
>GROUP BY BTA_Trades.FirmId;
>
>SELECT BTA_Trades.CounterpartFirmId, Sum(BTA_Trades.TradeVolume) AS
>PA_OUT
>FROM BTA_Trades
>WHERE (((BTA_Trades.AccountNumber)='PA-OUT'))
>GROUP BY BTA_Trades.CounterpartFirmId;
>
>Is there a way to combine the queries so I don;t have to run each of
>them ?
>
>Thank You in Advance.


That are you doing with the queries? Do you just want to see a datasheet with
te results?

If you just want a datasheet combining the results from the two queries, one
after the other, use a UNION query:

SELECT BTA_Trades.FirmId, Sum(BTA_Trades.TradeVolume) AS MM_NonPIP
FROM BTA_Trades
WHERE BTA_Trades.AccountType='MarketMaker' And
BTA_Trades.TradeType<>'Pip'
GROUP BY BTA_Trades.FirmId
UNION ALL
SELECT BTA_Trades.CounterpartFirmId, Sum(BTA_Trades.TradeVolume) AS
PA_OUT
FROM BTA_Trades
WHERE (((BTA_Trades.AccountNumber)='PA-OUT'))
GROUP BY BTA_Trades.CounterpartFirmId;

You can also base a report or form on this query (though the UNION query will
not be updateable; no UNION query, nor any Totals query, ever is).
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/For...-US/accessdev/
http://social.answers.microsoft.com/.../en-US/addbuz/
and see also http://www.utteraccess.com
 
Reply With Quote
 
carl
Guest
Posts: n/a
 
      26th Apr 2011
On Apr 26, 3:05*pm, "Bob Barrows" <reb01...@NOyahooSPAM.com> wrote:
> carl wrote:
> > I use these 2 queries...

>
> > SELECT BTA_Trades.FirmId, Sum(BTA_Trades.TradeVolume) AS MM_NonPIP
> > FROM BTA_Trades
> > WHERE BTA_Trades.AccountType='MarketMaker' And
> > BTA_Trades.TradeType<>'Pip'
> > GROUP BY BTA_Trades.FirmId;

>
> > SELECT BTA_Trades.CounterpartFirmId, Sum(BTA_Trades.TradeVolume) AS
> > PA_OUT
> > FROM BTA_Trades
> > WHERE (((BTA_Trades.AccountNumber)='PA-OUT'))
> > GROUP BY BTA_Trades.CounterpartFirmId;

>
> > Is there a way to combine the queries so I don;t have to run each of
> > them ?

>
> > Thank You in Advance.

>
> "Combine"? *This word can be interpreted in several different way. Whatdo
> you want the resulting query to return? A little more information please.
> Show us a couple rows of sample data returned from each query, then show us
> what you want the "combined" results to look like.- Hide quoted text -
>
> - Show quoted text -


Thanks for your help.


I am not too particular on how the output looks. Maybe like this ?


FirmId MM_NonPIP
BOX980 1996693
BOX549 1229560
BOX910 667716
BOX919 340773
BOX051 143669
BOX918 127853
BOX937 96074
BOX642 61667
BOX951 40521
BOX355 23533
BOX982 2598
BOX411 1506
BOX512 47

CounterpartFirmId PA_OUT
BOX501 23232
BOX792 7849
BOX411 4505
BOX916 2869
BOX982 1632
BOX938 1251
BOX983 1004
BOX060 743
BOX952 563
BOX226 499
BOX979 488
BOX123 394
BOX608 155
BOX512 88
BOX234 84
BOX953 72
BOX352 29
BOX050 26
BOX951 10
BOX074 10
BOX551 5
BOX445 1


 
Reply With Quote
 
Bob Barrows
Guest
Posts: n/a
 
      26th Apr 2011
carl wrote:
> On Apr 26, 3:05 pm, "Bob Barrows" <reb01...@NOyahooSPAM.com> wrote:
>> carl wrote:
>>> I use these 2 queries...

>>
>>> SELECT BTA_Trades.FirmId, Sum(BTA_Trades.TradeVolume) AS MM_NonPIP
>>> FROM BTA_Trades
>>> WHERE BTA_Trades.AccountType='MarketMaker' And
>>> BTA_Trades.TradeType<>'Pip'
>>> GROUP BY BTA_Trades.FirmId;

>>
>>> SELECT BTA_Trades.CounterpartFirmId, Sum(BTA_Trades.TradeVolume) AS
>>> PA_OUT
>>> FROM BTA_Trades
>>> WHERE (((BTA_Trades.AccountNumber)='PA-OUT'))
>>> GROUP BY BTA_Trades.CounterpartFirmId;

>>
>>> Is there a way to combine the queries so I don;t have to run each of
>>> them ?

>>
>>> Thank You in Advance.

>>
>> "Combine"? This word can be interpreted in several different way.
>> What do you want the resulting query to return? A little more
>> information please. Show us a couple rows of sample data returned
>> from each query, then show us what you want the "combined" results
>> to look like.

> I am not too particular on how the output looks. Maybe like this ?
>
>
> FirmId MM_NonPIP
> BOX980 1996693

<snip>
>
> CounterpartFirmId PA_OUT
> BOX501 23232

<snip>

I guess there is a failure to communicate. You seem to have shown some
sample rows from both queries, which is good.
Now, we need to know what the results would look like if "combined". I think
by "combined" you are asking for a single query to return both result sets
as a single resultset. So do you simply want them jumbled together so you
have no idea which query provided the data in the result? Like this?

FirmId MM_NonPIP
BOX501 23232
BOX980 1996693
BOX910 667716
BOX792 7849
BOX549 1229560
BOX411 4505

If so, John's union query suggestion is the way to go. if you want something
different, you need to tell us what that is.


 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      26th Apr 2011
On Tue, 26 Apr 2011 11:16:55 -0700 (PDT), carl <(E-Mail Removed)> wrote:

>I use these 2 queries...
>
>SELECT BTA_Trades.FirmId, Sum(BTA_Trades.TradeVolume) AS MM_NonPIP
>FROM BTA_Trades
>WHERE BTA_Trades.AccountType='MarketMaker' And
>BTA_Trades.TradeType<>'Pip'
>GROUP BY BTA_Trades.FirmId;
>
>SELECT BTA_Trades.CounterpartFirmId, Sum(BTA_Trades.TradeVolume) AS
>PA_OUT
>FROM BTA_Trades
>WHERE (((BTA_Trades.AccountNumber)='PA-OUT'))
>GROUP BY BTA_Trades.CounterpartFirmId;
>
>Is there a way to combine the queries so I don;t have to run each of
>them ?
>
>Thank You in Advance.


If you just want to display them on a Form, you could use two Subforms. If you
want to print them out, one after the other, with headers, use a Report with
two Subreports (or a report based on one, with a Subreport in the report
Header or Footer for the other).
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/For...-US/accessdev/
http://social.answers.microsoft.com/.../en-US/addbuz/
and see also http://www.utteraccess.com
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combining Queries =?Utf-8?B?Q2hlZXNl?= Microsoft Access 4 17th Sep 2007 08:15 AM
combining queries =?Utf-8?B?d2VzIGs=?= Microsoft Access 1 12th Jun 2007 09:56 PM
Help Combining Two Queries... Sean Massey Microsoft Access Queries 5 20th Dec 2006 05:26 PM
Combining 2 Queries DS Microsoft Access Form Coding 2 20th Jul 2006 03:27 PM
Combining Queries =?Utf-8?B?RnJhbmtN?= Microsoft Access Queries 3 20th Apr 2005 07:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:39 PM.