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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:02:58+00:00 2026-06-16T02:02:58+00:00

I have two queries that I want to join SELECT b.nickname,count(a.doctor_id) FROM a_table a

  • 0

I have two queries that I want to join

SELECT b.nickname,count(a.doctor_id) 
FROM a_table a 
join b_table b 
on (a.doctor_id=b.id_user) 
GROUP BY a.doctor_id

and

SELECT   doctor_id, SUM(medicine) medicine, SUM(radiology) radiology,sum(lab) lab, sum(act) act
FROM     (
  SELECT   MAX(doctor_id) doctor_id,
           SUM(IF(pm='F', cost, NULL)) medicine,
           SUM(IF(pm='R', cost, NULL)) radiology,
           SUM(IF(pm='L', cost, NULL)) lab,
           SUM(IF(pm='P', cost, NULL)) act
  FROM     c_table
  GROUP BY Trans_No
) t
GROUP BY doctor_id

I already tried to join

SELECT   b.nickname, count(a.doctor_id), SUM(medicine) medicine, SUM(radiology) radiology,sum(lab) lab, sum(act) act
FROM     (
  SELECT   MAX(doctor_id) doctor_id,
           SUM(IF(pm='F', cost, NULL)) medicine,
           SUM(IF(pm='R', cost, NULL)) radiology,
           SUM(IF(pm='L', cost, NULL)) lab,
           SUM(IF(pm='P', cost, NULL)) act
  FROM     c_table
  GROUP BY Trans_No
) t
join a_table a on (a.doctor_id=t.doctor_id)
join b_table b on (a.doctor_id=b.id_user)
GROUP BY a.doctor_id

all of these table has a large amount of data (more than 2 million data), I already set my CommandTimeout = 600 but it still has no respond

did I join it wrong or it’s just to many data? what am I supposed to do to get the result?

  • 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-16T02:02:59+00:00Added an answer on June 16, 2026 at 2:02 am

    This is not an answer, but it is too long for a comment.

    Your queries do not make sense. I think you need to look again at the problem. The first query:

    SELECT b.nickname,count(a.doctor_id) 
    FROM a_table a 
    join b_table b 
    on (a.doctor_id=b.id_user) 
    GROUP BY a.doctor_id
    

    is always going to return 1 for count(a.doctor_id), except when doctor_id is NULL. This is because you are grouping on that column. Do you mean to get the count of doctors for each nickname or the count of nicknames for each doctor?

    The subquery in the second query also doesn’t make much sense:

    SELECT   MAX(doctor_id) doctor_id,
             SUM(IF(pm='F', cost, NULL)) medicine,
             SUM(IF(pm='R', cost, NULL)) radiology,
             SUM(IF(pm='L', cost, NULL)) lab,
             SUM(IF(pm='P', cost, NULL)) act
    FROM     c_table
    GROUP BY Trans_No
    

    Why are you grouping the trans_no? Why aren’t you using it as an index?

    Perhaps you should write another question, explaining what you are trying to accomplish.

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

Sidebar

Related Questions

i have these two queries, that i want to join together, but am not
I have two queries that I want to join together, but I don't know
I have two selection queries and i want to select values from both and
I have two relatively complex queries that I am trying to join together into
I have two queries with subqueries for dateparts which I like to join. SELECT
I have two queries, as following: SELECT SQL_CALC_FOUND_ROWS Id, Name FROM my_table WHERE Name
I have two sql queries as following SELECT rc.stateId,rs.stateName FROM (SELECT DISTINCT cityid FROM
I have two SQL queries that I'm running from a C# winform, and I
I have two mysql queries that return a column of phone numbers. I want
I have a right outer join, that almost does what I want... SELECT users_usr.firstname_usr,

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.