Subject | Re: [firebird-support] Doubt Regarding Sum() Function |
---|---|
Author | Mark Rotteveel |
Post date | 2010-09-15T08:03:21Z |
> Hi PenWin,It is not a surprising result, it is the expected result for that query. In a query where you use join, you are essentially creating a temporary table that is used to perform the rest of the query.
>
> Thank You for your kind reply.
>
> I think I faild to represent my doubt, but give me one more chance, please
> find my doubt as follows:
>
> First of all, I got the surprisable result the way I wrote my first sql.
> I agree I would have written the same sql by others said, I agree.
> Ya obviously, others gave me the correct sql and which is also workingThen you should probably not be using join, but union (or maybe union in combination with a more specific join)
> fine, no doubt in that, I agree with this also.
>
> But at the same time, I also didn't forget to ask my main doubt in the
> previous mail that, "In future in some cases where I need to have multiple
> records in two different tables I may wish to get sum of perticular column
> from one table and some of perticular column from other table using join, then
> that time I would get wrong result the way I wrothe my first sql."
> For this we would consider an example that, I have two tables with the<snip>
> following same table structure, named "Main_Branch_Book_Details" and
> "Sub_Branch_Book_Details", now with this table structure and the data availability,
> if I need to find the how many copies sold for each book for
> the specified YearMonth in the Main Branch (i.e. "Main_Branch_Book_Details"
> table) as well as in the Sub Branch (i.e. "Sub_Branch_Book_Details" table) using
> single sql.
>
> "Main_Branch_Book_Details" table data is as follows:
>
> YearMonth Sold_On_Date Book_Name Copy_Sold
> 200904 01.04.2009
> ABC 565
><snip>
> "Sub_Branch_Book_Details" table data is as follows:
>
> YearMonth Sold_On_Date Book_Name Copy_Sold
> 200904 01.04.2009
> ABC 465
> Now I was talking about this above situation, now how do I achieve, howFirst of all, that is a bad database design. The data of the main and sub branch should be in the same table, because they represent the same kind of entities. You would then distinguish between data from the main and sub branch using a foreign key to (for example) a branch table. You would then group by the name of the book and the name of the branch.
> many copies are sold for the specified YearMonth in Man Branch as well as In
> Sub Branch.
But if this data structure is a given, than you should use union, not join to get the data.
Mark
--
Neu: GMX De-Mail - Einfach wie E-Mail, sicher wie ein Brief!
Jetzt De-Mail-Adresse reservieren: http://portal.gmx.net/de/go/demail