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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:54:47+00:00 2026-05-26T09:54:47+00:00

From a previous post, I have the following view in sqlite3: CREATE View AttendeeTableView

  • 0

From a previous post, I have the following view in sqlite3:

CREATE View AttendeeTableView AS

SELECT  (LastName || " " || FirstName) as AttendeeName,  
        CompanyName, 
        PhotoURI,
        CompanyAttendeeRelation.CompanyId,
        CompanyAttendeeRelation.AttendeeId 

FROM    Attendee 
JOIN    CompanyAttendeeRelation on CompanyAttendeeRelation.AttendeeId = Attendee.AttendeeId 

ORDER BY LastName;

Now, since the data is generated from a many-to-many relation between Attendee and Company, I can get results such as:

Doe John | company A | johnPic.png | 1 | 15
Doe John | company B | johnPic.png | 2 | 15

What I’d like to do is, in cases where there’s more than one company (like above), create a query that outputs:

Doe John | company A company B | johnPic.png | 1 2 | 15

And another that outputs:

Doe John | company A | company B | johnPic.png | 1 | 2 | 15

So I need to know essentially how to merge a specific column for rows that have different
values in that table.

Any ideas?

Just in case, company A company B in the first query is obviously text concatenation, That is, something along the lines of (row1.CompanyName || " " || row2.CompanyName)

  • 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-26T09:54:47+00:00Added an answer on May 26, 2026 at 9:54 am

    Use the aggregate function group_concat(X) for that:

    SELECT (a.LastName || " " || a.FirstName) AS AttendeeName
         , a.PhotoURI
         , group_concat(c.CompanyName) AS Companies
         , group_concat(c.CompanyId)   AS CompanyIds
    FROM   Attendee AS a
    JOIN   CompanyAttendeeRelation AS ca ON ca.AttendeeId = a.AttendeeId
    JOIN   Company                 AS c  ON c.CompanyId = ca.CompanyId
    GROUP  BY a.LastName, a.Firstname, a.PhotoURI;
    

    (Using table aliases to make it shorter and easier to read.)

    NULL values are excluded from the result. The manual:

    the concatenation of all non-NULL values

    The order of elements in CompanyIds and Companies is arbitrary, according to the manual:

    The order of the concatenated elements is arbitrary.

    Also note that “arbitrary” is not the same as “random”. group_concat, like other aggregate functions, processes the set of rows in the order received. Without any ORDER BY, that order is dictated by whatever query plan is executed. There is no natural order in tables of relational databases (you cannot rely on insert order at all). But both instances of group_concat() in the same SELECT list process rows in the same order so that the 1st ID in CompanyIds corresponds to the 1st name in Companies.

    You can impose your order with ORDER BY in a subquery. It’s an implementation detail, but it’s highly unlikely to change. Like:

    SELECT (LastName || " " || FirstName) AS AttendeeName
         , PhotoURI
         , group_concat(CompanyName) AS Companies
         , group_concat(CompanyId)   AS CompanyIds
    FROM  (
       SELECT a.LastName, a.FirstName, a.PhotoURI, c.CompanyName, c.CompanyId
       FROM   Attendee AS a
       JOIN   CompanyAttendeeRelation AS ca ON ca.AttendeeId = a.AttendeeId
       JOIN   Company                 AS c  ON c.CompanyId = ca.CompanyId
       ORDER  BY 1,2,3,4,5  -- or whatever you need
       ) AS sub
    GROUP  BY LastName, Firstname, PhotoURI;
    

    The manual about the (optional) ordinal numbers in ORDER BY:

    If the ORDER BY expression is a constant integer K then the expression is considered an alias for the K-th column of the result set (columns are numbered from left to right starting with 1).

    Use the GROUP BY list as leading ORDER BY expressions for best results.

    Don’t do anything with the derived table after ordering that might rearrange it (like joining the subquery to another table etc.)

    Finally, note that similar aggregate functions in other RDBMS can behave slightly differently. Related:

    • Concatenate multiple result rows of one column into one, group by another column
    • GROUP_CONCAT ORDER BY
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Related to my previous post here , I have the following SELECT : SELECT
I have this function from a plugin (from a previous post) // This method
In my previous post i ask how to create variables from an array (
I have tried switching from a previous Post request to a Get request. Which
I am following a previous post on stackoverflow about removing duplicates from a List<T>
From previous post, I learnt that for there are two ways, at least, to
I'm trying to refresh a page without sending POST from the previous time. I've
Note: This question has broadened in scope from previous revisions. I have tried to
From a previous question I have seen that the CLR has workstation and server
I have the following the standard, regular post sample app. I created some posts

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.