Subject | Re: looking for query help |
---|---|
Author | Adam |
Post date | 2005-09-27T05:36:52Z |
--- In firebird-support@yahoogroups.com, "women_lover_best"
<talbronstien@g...> wrote:
are two salesdetails records matching the tranid, but only one
payment, the payment fields would be duplicated.
select ...
from saleshead sh
left join salesdetails sd on (sh.pk-tranID=sd.fk-tranID)
left join payment p on (sh.pk-tranID=p.fk-tranID)
where sh.Trandate = :SomeDate
I assume you need left join so you still get the records if either
salesdetails or payment contains no records for the given transaction.
A more sensible approach would be to query in the salesdetails and
payment separately.
select sd.*
from saleshead sh
left join salesdetails sd on (sh.pk-tranID=sd.fk-tranID)
where sh.Trandate = :SomeDate
select p.*
from saleshead sh
left join payment p on (sh.pk-tranID=p.fk-tranID)
where sh.Trandate = :SomeDate
Assuming you have an appropriate index on saleshead.trandate, this
will be very quick (except fetch time if there is lots of data).
Adam
<talbronstien@g...> wrote:
> I have 3 tables saleshead(pk-tranID,other fields +have 2
> trandate),salesdetails(fk-tranid) and payment(fk-tranid)..now i
> get all transaction from saleshead for a particular datemy
> (trandate)..which is easy..but i also need to get all the rows from
> salesdetails and payment based on tranid i get from saleshead for a
> date..what are my options..joins,nested queries,using procedures..?
> what i want is all this data i should be able to get in one trip to
> application..where i have fill 3 collectionsIf you need to fill three collections, why do it in one hit? If there
> thks
are two salesdetails records matching the tranid, but only one
payment, the payment fields would be duplicated.
select ...
from saleshead sh
left join salesdetails sd on (sh.pk-tranID=sd.fk-tranID)
left join payment p on (sh.pk-tranID=p.fk-tranID)
where sh.Trandate = :SomeDate
I assume you need left join so you still get the records if either
salesdetails or payment contains no records for the given transaction.
A more sensible approach would be to query in the salesdetails and
payment separately.
select sd.*
from saleshead sh
left join salesdetails sd on (sh.pk-tranID=sd.fk-tranID)
where sh.Trandate = :SomeDate
select p.*
from saleshead sh
left join payment p on (sh.pk-tranID=p.fk-tranID)
where sh.Trandate = :SomeDate
Assuming you have an appropriate index on saleshead.trandate, this
will be very quick (except fetch time if there is lots of data).
Adam