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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:36:40+00:00 2026-06-01T15:36:40+00:00

I have a result from a query like the below, which does not have

  • 0

I have a result from a query like the below, which does not have a fixed number of columns

ID  COL1    COL2    COL3    COL4
-------------------------------------
1   VAL11   VAL12   VAL13   VAL14
2   VAL21   VAL22   VAL23   VAL24

Now I want the result to be something like this.

RESULT
-----------------------------------------------------
ID:1, COL1:VAL11, COL2:VAL12, COL3:VAL13, COL4:VAL14
ID:2, COL1:VAL21, COL2:VAL22, COL3:VAL23, COL4:VAL24

Please help.

  • 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-01T15:36:41+00:00Added an answer on June 1, 2026 at 3:36 pm

    The quick and dirty way, but without the column names and including NULL values:

    SELECT tbl::text
    FROM   tbl;
    

    The slow & sure way:

    SELECT array_to_string(ARRAY[
              'ID:'   || id
             ,'COL1:' || col1
             ,'COL2:' || col2
            ], ', ')  AS result
    FROM    tbl;
    

    If a column holds a NULL value, it will be missing in the result. I do not just concatenate, because NULL values would nullify the whole row.
    array_to_string() makes sure that commas are only inserted where needed.


    PostgreSQL 9.1 introduced the new function concat_ws() (much like the one in MySQL) with which we can further simplify:

    SELECT concat_ws(', '
              'ID:'   || id
             ,'COL1:' || col1
             ,'COL2:' || col2
            ) AS result
    FROM    tbl;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following query: select col1, sum( col2 ), count( col3 ) from
I have a result from an SQL query that I would like to sort
If you have a simple Linq query like: var result = from record in
I have a field that contains data like below: 124.97#54.03#5#16 its number which separated
I have a Linq to Entities query like this one: var results = from
I am running oracle and have a query which pulls some results from the
I have a sql server query question. I have a table like below. Giving
I have the below query, which basically it retrieves the 5 top most books
I have to do a first query which is SELECT * from table WHERE
I have below SQL query: SELECT * FROM ( SELECT S.aCol, S.bCol, S.cCol, ROW_NUMBER()

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.