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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:48:47+00:00 2026-06-13T02:48:47+00:00

I’m finding trouble finding a similar example to what I’m trying to achieve. I

  • 0

I’m finding trouble finding a similar example to what I’m trying to achieve. I have 3 tables. From one table I want to get the linking ID number. From another table I want to find the same ID’s and add up another column of numbers in that table where the ID number from the 1st table matches. Then on the 3rd table, which is text, I want to group all the text together where the ID matches the main ID number… and return all this in 1 go. My diagram should show what I mean:

So have 2 queries that will on their own return part the results, but Im struggling to build it into 1 single query.

    SELECT ticket_charges.ticket_id
         , sum(ticket_charges.charge_time) AS Seconds
    FROM
      ticket_charges
    LEFT OUTER JOIN tickets
    ON ticket_charges.ticket_id = tickets.id
    GROUP BY
      ticket_charges.ticket_id
    , tickets.id

The 77 and 937 for ticket ID 3 have been added up correctly!!

    SELECT tickets.id AS `Ticket Number`
         , left(tickets_messages.message, 500) AS `Ticket Message`
    FROM
      tickets
    INNER JOIN tickets_messages
    ON tickets.id = tickets_messages.id
    GROUP BY
      tickets_messages.ticket_id
    , tickets.id

The messages are joined together correctly.

I’ve tried some concatenation on messages, selects within selects, different methods to group by, a couple of sums etc.. but just can’t seem to get a result where by the I’m getting the results back correctly with both queries as 1 single query. Either the joined numbers from “charge_time” are very wrong and don’t match any resemblance to anything or I end up with hundreds of “message” and strange numbers on the “charge_time”

FYI.. If I try this, I get “Sub query returned more than 1 row” but it’s what I thought I should be doing.

    SELECT ticket_charges.ticket_id
        , sum(ticket_charges.charge_time) AS Seconds
    FROM
      ticket_charges
    LEFT OUTER JOIN tickets
    ON ticket_charges.ticket_id = tickets.id
       Where (SELECT left(tickets_messages.message, 500)
              FROM  
               tickets    
              INNER JOIN tickets_messages
              ON tickets.id = tickets_messages.id
              GROUP BY
               tickets.id)
    GROUP BY
     ticket_charges.ticket_id
    , tickets.id
  • 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-13T02:48:48+00:00Added an answer on June 13, 2026 at 2:48 am

    If you really need to do that with a single query, the solution is to do a subquery in one of the jointures.

    SELECT t.id, t.person_id, SUM(tc.charge_time), mc.concat
    FROM tickets t
    INNER JOIN tickets_charges tc ON tc.ticket_id = t.id
    INNER JOIN (
        SELECT ticket_id, GROUP_CONCAT(message SEPARATOR ' ') as concat
        FROM tickets_messages
        GROUP BY ticket_id) AS mc
      ON mc.ticket_id = t.id
    GROUP BY t.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.