Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6932893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:45:46+00:00 2026-05-27T11:45:46+00:00

I have a simple address book type of database. I’ve probably overnormalised, but it’s

  • 0

I have a simple address book type of database. I’ve probably overnormalised, but it’s as much about productivity as it is learning.

I have a table, PEOPLE, with an ID (generated identity), first/last names, title, etc. Also has a foreign key “spouse” on the ID field in its own table. Obviously, nullable.

I have a table, ADDRESSES, with an ID (generated identity), and all the details required for snail mail.

I have a table, PERSONADDRESS, with two foreign keys, PERSON pointing to PEOPLE.ID, and ADDRESS pointing to ADDRESSES.ID.

Theoretically, I’ll have an EMAILS table with the foreign key to PEOPLE and the email. Theoretically, people (geeks like me) can have more than one email. And other relations between similar data in the future. (PHONES, etc.).

So, with that, the problem is this. I want to produce some address labels. (Yes, it’s getting a little late for Christmas cards.) So, to get Libreoffice to do this, I think I need to create a view that LO can read its data from, where every field I want to spit out is already available.

This is somewhat simple enough, except that, at the moment, I have a bit too much duplication. My view is created as such:

CREATE OR REPLACE VIEW ADDRBOOK.LABELS AS
  WITH T AS (
    SELECT DISTINCT
      P1.ID AS AID,
      P1.TITLE AS ATITLE, P1.GIVENNAME AS AGIVEN, P1.LASTNAME AS ALAST,
      P2.TITLE AS BTITLE, P2.GIVENNAME AS BGIVEN, P2.LASTNAME AS BLAST,
      A.STREET, A.MUNICIPALITY, A.STATE, A.COUNTRY, A.POSTALCODE
    FROM
      ADDRBOOK.ADDRESSES A
        JOIN
      ADDRBOOK.PERSONADDR PA
        ON PA.ADDRESS = A.ID
        JOIN
      ADDRBOOK.PEOPLE P1
        ON PA.PERSON = P1.ID
        LEFT OUTER JOIN
      ADDRBOOK.PEOPLE P2
        ON P1.SPOUSE = P2.ID
    ORDER BY P1.ID
  )
  SELECT DISTINCT
    ATITLE, AGIVEN, ALAST,
    BTITLE, BGIVEN, BLAST,
    STREET, MUNICIPALITY, STATE, COUNTRY, POSTALCODE
  FROM T
;

However, this means that if persons A and B are married, I’m going to get one entry where A is showing up under ATITLE, AGIVEN, ALAST, and B is BTITLE, BGIVEN, BLAST, and another entry where they’ve reversed positions. The distinct obviously doesn’t work because they’re simply in different columns. I’m having trouble imagining the changes I would need to make this exclusion.

Note that disconnecting one of the two people from the address, which would be a simple solution for this particular issue, would run counter to the general table data concept: to hold all these relationships for whatever purpose, and then extract what I need when I need it. Granted, it’s 90% labels at this point, but as long as it’s a learning excersise, I’m hoping someone can help me out here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:45:47+00:00Added an answer on May 27, 2026 at 11:45 am

    Add this where clause to your temp table query. Nearly all of these types of AB/BA problems can be solved by similar comparison.

    WHERE P2.ID IS NULL OR P1.ID < P2.ID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using MySQL, I have a simple table that logs the IP Address that users
I have simple database - one table with 6 collumns. 3 of them i
I have a simple address book app that I want to make searchable. The
I am working with a simple address book in which i have separate lists
I'm designing a contact manager/address book-like application but can't settle on the database design.
I'm designing a contact manager/address book-like application but can't settle on the database design.
I'm making a simple address book GUI and I don't have a very good
I have the sample address book project loaded up and it is failing to
Say I have a simple address class like below: public class Address { public
I have simple table in Sybase -- Creating table 'SimpleText' CREATE TABLE [dbo].[SimpleText] (

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.