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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:40:38+00:00 2026-05-31T13:40:38+00:00

I am creating 2 queries: 1 select count(c.id) as cid1, p.name as pname1, u.name

  • 0

I am creating 2 queries:

1

select count(c.id) as cid1, p.name as pname1, u.name as uname1 
from crm_lead c, account_period p, res_users u 
where c.create_date between p.date_start and p.date_stop and 
      (c.user_id = u.id or c.sales_vertical=u.id) and 
      u.id = 1 
group by p.name, u.name

2

select count(c.id) as cid2, p.name as pname2, u.name as uname2 
from crm_lead c, account_period p, res_users u 
where c.create_date between p.date_start and p.date_stop and
      (c.user_id = u.id or c.sales_vertical=u.id) and 
      stage_id =12 and 
      u.id = 1 
where a.pname = b.pname 
group by p.name, u.name

I am getting the following resuls for the above 2 queries

result for q1 :

 cid1         pname1      uname1                                       
 11           07/2011     admin                                        
 5            08/2011     admin                                        
 9            09/2011     admin

result for q2 :

 cid2        pname2    uname2                                          
 9           07/2011   admin                                           
 3           09/2011   admin

after combining both the queries I am getting following output:

 cid1  cid2  pname1    pname2     uname1     uname2                    
 11     9     07/2011   07/2011   admin      admin                     
 9      3     09/2011   09/2011   admin      admin

But I want the result as

 cid1   cid2  pname1    pname2    uname1     uname2                    
 11     9     07/2011   07/2011   admin      admin                     
 5      0     08/2011   08/2011   admin      admin                     
 9      3     09/2011   09/2011   admin      admin

How can it be done?

My combined query is below:

select a.cid1, b.cid2, a.pname1, b.pname2, a.uname1, b.uname2 
from (select count(c.id) as cid1, p.name as pname1, u.name1 as uname 
      from crm_lead c, account_period p, res_users u 
      where c.create_date between p.date_start and p.date_stop and 
            (c.user_id = u.id or c.sales_vertical=u.id) and 
            u.id = 1 
      group by p.name, u.name) as a,
     (select count(c.id) as cid2, p.name as pname2, u.name as uname2 
      from crm_lead c, account_period p, res_users u 
      where c.create_date between p.date_start and p.date_stop and
            (c.user_id = u.id or c.sales_vertical=u.id) and 
            stage_id =12 and 
            u.id = 1 
      group by p.name, u.name)as b 
where a.pname1 = b.pname2
  • 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-31T13:40:39+00:00Added an answer on May 31, 2026 at 1:40 pm

    To get your requested result the query could look like this:

    SELECT a.cid1
          ,COALESCE(b.cid2, 0) AS cid2
          ,a.pname1
          ,COALESCE(b.pname2, a.pname2) AS pname2
          ,a.uname1
          ,COALESCE(b.uname2, a.uname2) AS uname2
    FROM  (<query1>)  a
    LEFT   JOIN (<query2>) b ON a.pname1 = b.pname2
    

    I have my doubts, however, that you actually want that exact result.

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

Sidebar

Related Questions

Here's my query: SELECT solGroup,; SUM(IIF((; SELECT COUNT(*) FROM cgift c2; WHERE c2.solgroup !=
I'm creating a webserivce that will be using Linq-To-Sql to perform select only queries.
When creating reports I find myself frequently joining to ad-hock sub queries like this:
I'm creating a javascript regex to match queries in a search engine string. I
I'm an accomplished user of SQL; I'm confident creating schema and optimizing queries in
Creating a patch is very easy in SubVersion, With Tortoise, you right-click and select
I was just wondering which approach is better. Creating a complex select query with
I have some demanding mysql queries that have to select same frequently updated datasets
Sometimes one when creating SQL queries one assumes that one of the Index should
I'm trying to speed up SELECT queries in MySQL tables which already have some

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.