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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:27:48+00:00 2026-06-17T07:27:48+00:00

This is my Table: and I am running this query, SELECT fruits,COUNT(*) as count

  • 0

This is my Table:

This is my table

and I am running this query,

SELECT fruits,COUNT(*) as count FROM meva where owner = 'bill' GROUP BY fruits ORDER BY count 

and i am getting result as

enter image description here

Is it possible to get the other fruits items as 0 if not matched with owner like this,

Fruit   | count
Apple   ,   2
Mango   ,   0
Banana  ,   0
Strawberry ,0
Appricot,   0
Alfonso ,   0

A little modification in my query is most appreciated.
thanks

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

    use SUM() and CASE

    SELECT  fruits, 
            SUM(CASE WHEN owner = 'bill' THEN 1 ELSE 0 END) as `count `
    FROM     meva 
    GROUP BY fruits 
    ORDER BY fruits
    

    or by using IF (in MySQL only)

    SELECT  fruits, 
            SUM(IF(owner = 'bill',1,0)) as `count `
    FROM     meva 
    GROUP BY fruits 
    ORDER BY fruits
    
    • SQLFiddle Demo (CASE and IF)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running this query: select * from schema.table but i'm only getting the first
I have this table in MySql db: After running this query: SELECT score, count(*)
I'm running this query: SELECT COUNT(*) as num FROM items WHERE status='public' AND DATE(dateCreated)
I am running this query which selects a few fields from one table and
I am currently running this query: SELECT t.videolink, t.userid, t.tag FROM (SELECT * FROM
I'm running a query to select an array of id's from one table, so
I am running this query SELECT * FROM (`T_INV_DTL`) LEFT JOIN ( SELECT GROUP_CONCAT(DISTINCT
I want to do this query: SELECT * FROM mail WHERE tag_draft = 0
Let us say I have a query like this: SELECT * FROM ( SELECT
I have the following query: SELECT * FROM shop_user_member_spots WHERE delete_flag = 0 ORDER

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.