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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:58:49+00:00 2026-06-17T10:58:49+00:00

I want to combine about 3 MySQL query to one , but some complex

  • 0

I want to combine about 3 MySQL query to one , but some complex . (below is my test querys and table datas example)

Table1: accounts

id  |   account | email  | refer
11  |   aasdasd | 5@as.a | 0
12  |   gasd    | 4@ds.a | 11
13  |   xcsxs   | 3@ss.a | 11
14  |   cbasd   | 2@as.a | 11
15  |   asdv    | 1@gs.a | 11
16  |   sdfgx   | 6@hs.a | 8

…

Table2: characters

guid    |account| name | rank   | time
561     |   11  | asda | 945    | 12
562     |   11  | asda | 746    | 19
563     |   11  | asda | 452    | 1
564     |   12  | asda | 123    | 15
565     |   12  | asda | 456    | 18
566     |   13  | asda | 123    | 6
567     |   13  | asda | 789    | 18
568     |   13  | asda | 123    | 17
569     |   15  | asda | 456    | 13
570     |   16  | asda | 123    | 15
571     |   17  | asda | 456    | 16

…
My Tested Querys:

 SELECT id FROM accounts WHERE refer='11'

to identify the accounts was refer with value ’11’
and second query to show and sum totaltime of accounts characters where was have refer with value 11 :

SELECT a.account, a.email, SUM(c.time) , c.rank
FROM accounts a, characters c
WHERE a.id=c.account
ORDER BY MAX(c.rank) DESC

Whats i want:
I want to combine the above two query two one and have a result like below :
rank column is highest rank of character from account and totaltime is sum of all characters time of that account

Account | Email | Rank | TotalTime
gasd    |4@ds.a | 456  | 33
xcsxs   |3@ss.a | 789  | 41
cbasd   |2@as.a |  0   | 0
asdv    |1@gs.a | 456  | 13

second query with SUM I think have problem , I add it now .

  • 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-17T10:58:50+00:00Added an answer on June 17, 2026 at 10:58 am

    try this

        SELECT a.account, a.email,  c.rank,SUM(c.time) totaltime
        FROM accounts a
        INNER JOIN characters c
        ON a.id = c.account
    
        WHERE a.refer=11
        ORDER BY MAX(c.rank) DESC
    

    edit :

       SELECT a.account, a.email,  MAX(c.rank) rank,SUM(c.time) totaltime
        FROM accounts a
         left JOIN characters c
        ON a.id = c.account
    
        WHERE a.refer=11
      group by a.account
       ORDER BY MAX(c.rank) DESC
    

    LOOK DEMO SQLFIDDLE

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

Sidebar

Related Questions

I want to combine AND OR mysql queries in CI. I have already seen
I want to combine these two queries into one: mysql_query(INSERT INTO categories (name, parent)
I want to combine 2 parts of the same array to make a complex
I have a report in SSRS 2008 and I want to combine some strings.
I have 3 tables that I want to combine, see below for details: product
I want to have some constants in a Django Projects. For example, let's say
I want to combine multiple tables result count in one result with column wise
I want to combine registry key path fragments together without worrying about correct backslash
I want to combine the first and last names and present them in the
I want to combine Hadoop based Mahout recommenders with Apache Hive.So that My generated

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.