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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:26:25+00:00 2026-05-26T19:26:25+00:00

I have two tables. table1 aid alphabet Name 1 A Apple 2 A Air

  • 0

I have two tables.

table1


    aid   alphabet      Name
    1        A          Apple
    2        A          Air
    3        B          Ball
    4        C          Cat
    5        C          Cow
    6        F          Footbal
    7        G          God          

table2


    did    aid    typeId   groupId   description  
    1       1      3         4        apple description
    2       2      3         4        ffdadfdfd
    3       3      5         6        fdsfsdafasdf

I need to select table2 mapping count of each alphabet with a condition typeId 3 and groupId 4.

I wrote this kind of a query but its not fetching all alphabet. Those alphabet have mapping that only its fetching.

select a.alphabet, count(did) from table1 a left join table2 b on a.aid=b.aid
where b.typeId=3 and b.groupId=4 group by a.alphabet

How can I write that kind of a query?

I need this kind of an output.


    alphabet   Count
     A          2
     B          0
     C          0
     F          0 .. etc
   
  • 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-26T19:26:26+00:00Added an answer on May 26, 2026 at 7:26 pm

    By adding the typeId and groupId checks in the where clause, you are effectively making your left join into an inner join, by requiring all rows have values in this joined table. However, this is not the case here. If you move the type and group checks to the on clause (in the join), you should get the desired result.

    select
       a.alphabet,
       count(b.did)
    from
       table1 a
       left join table2 b 
          on a.aid=b.aid and b.typeId=3 and b.groupId=4
    group by
       a.alphabet
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables - table1 and table2 table1 has 14 columns and table2
I have two tables table1 +-------+-------+ | NAME | PRICE | +-------+-------+ | ITEM1
I have two tables table1 and table2 each having a column named email along
I have two tables: table1, table2. Table1 has 10 columns, table2 has 2 columns.
I have two tables (Table1 and Table2.) I want to delete all rows in
I have two tables. Table1 and Table2 Table1 id tid 1 100 2 200
If I have two tables: *******awards ---------------------- aid | position | name ---------------------- 1
I have 4 tables Table1 (employee) id name -------------------- 1 a 2 b Table2
I have two tables, related by a common key. So TableA has key AID
i have two tables table1 fields fid,fname,fage a ,abc ,20 b ,bcv ,21 c

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.