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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:11:35+00:00 2026-05-12T23:11:35+00:00

My goal is to achieve a result set like the following CODE | TOTAL1

  • 0

My goal is to achieve a result set like the following

CODE | TOTAL1 | TOTAL2  
1    | 56     | 34  
2    | 12     | 15  
3    | 90     | 3

There are 2 tables e.g tableA and tableB
The counts are different by tableB.type

SELECT   code, COUNT (*) AS total1  
FROM tableA a
WHERE a.ID IN (select ID from tableB
    where type = 'XYZ')
GROUP BY code


SELECT   code, COUNT (*) AS total2  
FROM tableA a
WHERE a.ID IN (select ID from tableB
    where type = 'ABC')
GROUP BY code

I’d like to display the count for each code per type in the same query

Thanks in advance

  • 1 1 Answer
  • 7 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-12T23:11:35+00:00Added an answer on May 12, 2026 at 11:11 pm

    Subqueries :

    SELECT   code, (select COUNT (*) AS total1  
    FROM tableA a1
    WHERE a.ID IN (select ID from tableB
        where type = 'XYZ')
        and a1.code = tableA.code) as Total1,  
    (select COUNT (*) AS total2  
    FROM tableA a2
    WHERE a.ID IN (select ID from tableB
        where type = 'ABC')
        and a2.code = tableA.code) as Total2)
    from tableA
    group by Code
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My goal is to achieve a list of parent categories from a nested category
Core Question I need help coming up with a concept to achieve my goal.
I am trying to achieve a very simple goal, however it does not seem
Goal: Create Photomosaics programmatically using .NET and C#. Main reason I'd like to do
I have two tables looking like this: A B id_attr value id id_attr value
I have two arrays that need to be mapped. In code var result =
I want to return all elements in a list like the result below in
Consider the following code: template<size_t head,size_t ... Dims> struct make_vec { typedef typename make_vec<Dims...>::type
The goal I am trying to achieve is to run a mysql query, place
Goal Java client for Yahoo's HotJobs Resumé Search REST API . Background I'm used

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.