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

  • Home
  • SEARCH
  • 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 8108695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:11:36+00:00 2026-06-06T01:11:36+00:00

I have a table in a postgresql-9.1.x database which is defined as follows: #

  • 0

I have a table in a postgresql-9.1.x database which is defined as follows:

# \d cms
                                      Table "public.cms"
   Column    |            Type             |                    Modifiers                     
-------------+-----------------------------+--------------------------------------------------
 id          | integer                     | not null default nextval('cms_id_seq'::regclass)
 last_update | timestamp without time zone | not null default now()
 system      | text                        | not null
 owner       | text                        | not null
 action      | text                        | not null
 notes       | text

Here’s a sample of the data in the table:

 id  |        last_update         |        system        |   owner   |               action                | 
     notes
 ----+----------------------------+----------------------+-----------+-------------------------------------    +-
----------------
 584 | 2012-05-04 14:20:53.487282 | linux32-test5   | rfell     | replaced MoBo/CPU                   | 
  34 | 2011-03-21 17:37:44.301984 | linux-gputest13 | apeyrovan | System deployed with production GPU | 
 636 | 2012-05-23 12:51:39.313209 | mac64-cvs11     | kbhatt    | replaced HD                         | 
 211 | 2011-09-12 16:58:16.166901 | linux64-test12  | rfell     | HD swap                             | 
drive too small

What I’d like to do is craft a SQL query that returns only the unique/distinct values from the system and owner columns (and filling in NULLs if the number of values in one column’s results is less than the other column’s results), while ignoring the association between them. So something like this:

 system          |    owner
-----------------+------------------
 linux32-test5   |   apeyrovan
 linux-gputest13 |   kbhatt 
 linux64-test12  |   rfell
 mac64-cvs11     |

The only way that I can figure out to get this data is with two separate SQL queries:
SELECT system FROM cms GROUP BY system;
SELECT owner FROM cms GROUP BY owner;

  • 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-06-06T01:11:37+00:00Added an answer on June 6, 2026 at 1:11 am

    Far be it from me to inquire why you would want to do such a thing. The following query does this by doing a join, on a calculated column using the row_number() function:

    select ts.system, town.owner
    from (select system, row_number() over (order by system) as seqnum
          from (select distinct system
                from t
               ) ts
         ) ts full outer join
         (select owner, row_number() over (order by owner) as seqnum
          from (select distinct owner
                from t
               ) town
         ) town
         on ts.seqnum = town.seqnum
    

    The full outer join makes sure that the longer of the two lists is returned in full.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have latitude and longitude columns in location table in PostgreSQL database, and I
I have a table in my postgresql 8.4 database like this: id(serial), event_type_id(id, foreign
I have the following table in my postgreSQL 8.3.14 database timestamp status 2012-03-12 19:15:01
I have the following table and sequence in my postgresql-8.4 database: CREATE TABLE complexobjectpy
(I am using PostgreSQL) I have a table which stores transactions to an account.
Suppose I have two queries on a database table. The queries are defined in
I have a Spring application which uses Hibernate on a PostgreSQL database. I'm trying
I have a PostgreSQL\PostGIS spatial database which contains Hebrew text columns. The system runs
I have a Ruby/Rails app. I have an artists table in my postgresql database
I have a Django-created tables in PostgreSQL 8.4 database, where one table extends another.

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.