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 8516773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:31:27+00:00 2026-06-11T05:31:27+00:00

Given is a Postgres table like this nummer vorname name cash ——|———–|———–|—– 1 paul

  • 0

Given is a Postgres table like this

nummer  vorname    name        cash
------|-----------|-----------|-----
1       paul       smith       500
2       andy       london      700
2       mike       dover       700
3       clara      winchester  200

To query this table my sql looks like this right know:

SELECT 
  nummer,
  vorname,
  name,  
  cash as total
FROM 
  data.myTable
GROUP BY
  nummer, 
  name,
  vorname,
  cash
ORDER BY
  nummer; 

Is it possible to concat the two rows where nummer is the same (in this case 2).
Means my output should look like this (cash will also have the same values if the numbers are equal):

nummer  vorname    name        cash
------|-----------|-----------|-----
1       paul       smith       500
2       andy       london      700
        mike       dover       
3       clara      winchester  200
  • 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-11T05:31:29+00:00Added an answer on June 11, 2026 at 5:31 am

    Use GROUP BY and the aggregate functioin string_agg():

    SELECT nummer
          ,string_agg(vorname, E'\n') AS vorname
          ,string_agg(name, E'\n') AS name
          ,cash
    FROM   mytable
    GROUP  BY nummer, cash
    ORDER  BY nummer, cash;
    

    I added cash to the GROUP BY to get to the original value and safeguard against the case where it would be different for the same nummer.

    As to your comment:

    is it possible to unique the query also by names. means if 2|andy
    london|700 is listed twice one should be removed.

    SELECT nummer
          ,string_agg(vorname, E'\n') AS vorname
          ,string_agg(name, E'\n') AS name
          ,cash
    FROM  (
       SELECT DISTINCT
              nummer, vorname, name, cash
       FROM   mytable
       ) AS m
    GROUP  BY nummer, cash
    ORDER  BY nummer, cash;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a table like this: name | score_a | score_b -----+---------+--------
I realize there are is no TRIGGER ON SELECT in Postgres. Given a table
Given a MySQL table of real estate data, I would like to generate a
Given a table like so: id | value ------------------- 1 | food 2 |
I have a Postgres table with more than 8 million rows. Given the following
Trying to create this example table structure in Postgres 9.1: CREATE TABLE foo (
Given that the web application doesn't have su privileges, I'd like to execute a
Given this method to work on a HTML page in a webbrowser: bool semaphoreForDocCompletedEvent;
The below Postgres SQL query is returning all records available in the table. Can
(Not sure if the name of this question really makes sense, but what I

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.