On Mon, 2012-01-23 at 13:14 -0500, Calvin Kim wrote:
On 01/23/2012 08:26 AM, Werner F. Bruhin wrote:
I have the following:
tablea
- id
- name
tableb
- id
- type
- total
- tablea_id
In tableb there can be multiple records for a record in tablea.
Like to get to this:
tablea.id, tablea.name, tableb1.total1 (if type = 1), tableb2.total2
(if type = 2)
I tried to setup a view where I link tableb twice to tablea, but I
can't figure out how to define things with regards to the relation.
In SQL it would be something along these lines:
SELECT DISTINCT `table1`.`name`, `tableb1`.`total`, `tableb2`.`total`
FROM `tablea`
LEFT OUTER JOIN `tableb` as `tableb1` ON `tablea`.`id` =
`tableb1`.`tablea_id` AND `tableb1`.`type` = 1
LEFT OUTER JOIN `tableb` as `tableb2` ON `tablea`.`id` =
`tableb2`.`tablea_id` AND `tableb2`.`type` = 1
Is this possible with base in LibrOffice 3.3.2, but could upgrade if a
newer version provides this functionality.
Thanks in advance for any tips.
Werner
I'm no guru, and I just thought about it in my head. So it will
definitely not work...
SELECT
tablea.id,
tablea.name,
(SELECT total FROM tableb WHERE type = 1 LIMIT 1) AS `Type1 Total`,
(SELECT total FROM tableb WHERE type = 2 LIMIT 1) AS `Type2 Total`
FROM
tablea, tableb
WHERE
tablea.id = tableb.tablea_id;
cK
My thinking is that you do not have enough fields in tableb. What
you should have is
tableb
- id
- type
- total
- tablea1_id foreign key
- tablea2_id foreign key
You will have two relationships:
tablea.id = tableb.tablea1_id where type = 1
tablea.id = tableb.tablea2_id where type = 2
A form for this would have tablea as the main form and tableb as
the sub form. Records in the sub form will fall into one of two
categories for a given value of the field Name: type =1 or type =2 but
not both.
I'm also thinking that a query using both tables could be used. I'm
not sure how you would want to sort the query. You might want to sort
first by the field type (ascending) and second by the field Name
(ascending). This would first give you all the data for when type =1.
Within this sort, you would have an alphabetical sorting for values of
the Name field.
--Dan
--
For unsubscribe instructions e-mail to: users+help@global.libreoffice.org
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted
Context
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.