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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:55:43+00:00 2026-05-23T13:55:43+00:00

The following query only returns Region Names for regions where there have been orders.

  • 0

The following query only returns Region Names for regions where there have been orders.

   SELECT r.RegionName,
          COUNT (DISTINCT o.uid)
     FROM Orders AS o
LEFT JOIN Customers AS c ON o.CustomerID = c.uid
LEFT JOIN Regions AS r ON c.Region = r.uid
    WHERE (r.RegionName NOT LIKE 'NULL') 
      AND (r.RegionName <> '') 
      AND (r.RegionName NOT LIKE 'Region 1') 
      AND (o.DateOrdered LIKE '7%2011%')
 GROUP BY r.RegionName
 ORDER BY r.RegionName

How can I modify it so that all region names show up even when the “COUNT” is “0”?

  • 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-23T13:55:44+00:00Added an answer on May 23, 2026 at 1:55 pm

    You need to either change your JOIN to Regions to be a RIGHT JOIN or make Regions the FROM table and then JOIN to the other tables from there.

    I prefer the second method, since it seems more intuitive to me. You care about Regions here and you’re trying to get information about Regions, so that should be in the FROM (IMO):

    SELECT
        R.RegionName,
        COUNT(O.uid)
    FROM
        Regions R
    LEFT OUTER JOIN Customers C ON C.Region = R.uid  -- I really don't like this naming convention
    LEFT OUTER JOIN Orders O ON
        O.CustomerID = C.uid AND
        O.DateOrdered LIKE '7%2011%'  -- Is your date really stored as a string? Ugh!
    WHERE
        R.RegionName <> 'NULL' AND   -- This is VERY bad...
        R.RegionName <> '' AND
        R.RegionName <> 'Region 1'
    GROUP BY
        R.RegionName
    ORDER BY
        R.RegionName
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been tried the following query and it succeeds (only returns the one
I have readonly access to the master database however the following query only returns
The following query returns >7000 rows when each table only has 340 rows. SELECT
I have the following query in ORACLE SQL: Select Trunc(Cs.Create_Dtime), Count(Case When Cs.Cs_Listing_Id Like
The following query returns strange results for me: SELECT `Statistics`.`StatisticID`, COUNT(`Votes`.`StatisticID`) AS `Score`, COUNT(`Views`.`StatisticID`)
The following query returns the total amount of orders, per week, for the past
I have the following query: select * from ACADEMIC a left join RESIDENCY r
I have the following query that returns a comma separated list of email ids
The following query returns data right away: SELECT time, value from data order by
I need some help, I have the following query: SELECT l.*, d.*, i.*, DATE_FORMAT(l.date_created,

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.