Board index » delphi » Single or multiple queries?

Single or multiple queries?

I wish to display in a DBGrid all of the records subject to certain
conditions, and at the botton of the grid, show the total calculated with
the sum of the field "amount". I am now doing it with two different queries.
Would it be possible to do it with a single one ?

I like to know since I have a basic knowledge of Delphi and I am still
working with dbase tables and related TQuery. I am starting to feel the need
to have multiple totals and I wonder what the application performance will
be if I need to add query to query.
Thanks for any answer.

 

Re:Single or multiple queries?


Quote
Stark wrote:
> I wish to display in a DBGrid all of the records subject to certain
> conditions, and at the botton of the grid, show the total calculated with
> the sum of the field "amount". I am now doing it with two different
> queries. Would it be possible to do it with a single one ?

> I like to know since I have a basic knowledge of Delphi and I am still
> working with dbase tables and related TQuery. I am starting to feel the
> need to have multiple totals and I wonder what the application performance
> will be if I need to add query to query.
> Thanks for any answer.

While you could do it with a single query, it would require you to download
and add-up all the fields.  With a large recordset that can be expensive.

So, it's better to do a separate query to get those totals.  In this way,
the server simply tells you what you need to know without shoving excessive
data down the wire.

Re:Single or multiple queries?


I am working on a stand alone environment and using dBase tables and
associated TQueries. What would the statements be for a single query ?

"Sundial Services" <info_...@sundialservices.com> ha scritto nel messaggio
news:vbvifssn08pp07@corp.supernews.com...

Quote
> Stark wrote:

> > I wish to display in a DBGrid all of the records subject to certain
> > conditions, and at the botton of the grid, show the total calculated
with
> > the sum of the field "amount". I am now doing it with two different
> > queries. Would it be possible to do it with a single one ?

> > I like to know since I have a basic knowledge of Delphi and I am still
> > working with dbase tables and related TQuery. I am starting to feel the
> > need to have multiple totals and I wonder what the application
performance
> > will be if I need to add query to query.
> > Thanks for any answer.

> While you could do it with a single query, it would require you to
download
> and add-up all the fields.  With a large recordset that can be expensive.

> So, it's better to do a separate query to get those totals.  In this way,
> the server simply tells you what you need to know without shoving
excessive
> data down the wire.

Re:Single or multiple queries?


Conceptualy, "select sum(fieldname) from tablename."

Unfortunately, with local tables what's gonna happen is that every row is
going to be scanned, by someone.  

Quote
Franco Jommi wrote:
> I am working on a stand alone environment and using dBase tables and
> associated TQueries. What would the statements be for a single query ?

> "Sundial Services" <info_...@sundialservices.com> ha scritto nel messaggio
> news:vbvifssn08pp07@corp.supernews.com...
>> Stark wrote:

>> > I wish to display in a DBGrid all of the records subject to certain
>> > conditions, and at the botton of the grid, show the total calculated
> with
>> > the sum of the field "amount". I am now doing it with two different
>> > queries. Would it be possible to do it with a single one ?

>> > I like to know since I have a basic knowledge of Delphi and I am still
>> > working with dbase tables and related TQuery. I am starting to feel the
>> > need to have multiple totals and I wonder what the application
> performance
>> > will be if I need to add query to query.
>> > Thanks for any answer.

>> While you could do it with a single query, it would require you to
> download
>> and add-up all the fields.  With a large recordset that can be expensive.

>> So, it's better to do a separate query to get those totals.  In this way,
>> the server simply tells you what you need to know without shoving
> excessive
>> data down the wire.

--
----------------------------------
Fast automatic table repair at a click of a mouse!
http://www.sundialservices.com/products/chimneysweep

Re:Single or multiple queries?


If you want to load the data in one query you can, but it is not good
practice. I would rather have two query components which you can open at the
same time and then simply change the DataSource component to point to the
one you want. But if you insist on using one query, then try the following:

You can of course load the combination of your two sets of conditions with a
single query as follows:

SELECT * FROM MyTable
WHERE (condition1)
   OR (condition2)

Then you could use the Filter property to filter out unwanted data, but I
think you would have to close and reopen the query every time you change the
filter (I am not sure about this, because using filters is not a good idea,
so I never use them).
--
Regards

John Bester
mailto:john.bes...@adept.co.za

Quote
"Franco Jommi" <franco.jom...@tin.it> wrote in message

news:MY1wa.159438$K35.3774125@news2.tin.it...
Quote
> I am working on a stand alone environment and using dBase tables and
> associated TQueries. What would the statements be for a single query ?

> "Sundial Services" <info_...@sundialservices.com> ha scritto nel messaggio
> news:vbvifssn08pp07@corp.supernews.com...
> > Stark wrote:

> > > I wish to display in a DBGrid all of the records subject to certain
> > > conditions, and at the botton of the grid, show the total calculated
> with
> > > the sum of the field "amount". I am now doing it with two different
> > > queries. Would it be possible to do it with a single one ?

> > > I like to know since I have a basic knowledge of Delphi and I am still
> > > working with dbase tables and related TQuery. I am starting to feel
the
> > > need to have multiple totals and I wonder what the application
> performance
> > > will be if I need to add query to query.
> > > Thanks for any answer.

> > While you could do it with a single query, it would require you to
> download
> > and add-up all the fields.  With a large recordset that can be
expensive.

> > So, it's better to do a separate query to get those totals.  In this
way,
> > the server simply tells you what you need to know without shoving
> excessive
> > data down the wire.

Other Threads