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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:30:09+00:00 2026-05-29T22:30:09+00:00

Table layouts reject_data +———–+—————–+——————+—————+ | reject_id | reject_location | reject_equipment | reject_time | +———–+—————–+——————+—————+

  • 0

Table layouts

reject_data

+-----------+-----------------+------------------+---------------+
| reject_id | reject_location | reject_equipment | reject_time   |
+-----------+-----------------+------------------+---------------+
| 1         | 7               | 6                | 1326795921000 |
+-----------+-----------------+------------------+---------------+
| 2         | 7               | 1                | 1326796641000 |
+-----------+-----------------+------------------+---------------+
| 3         | 7               | 6                | 1326799521000 |
+-----------+-----------------+------------------+---------------+
| 4         | 6               | 5                | 1326800781000 |
+-----------+-----------------+------------------+---------------+
| 5         | 7               | 3                | 1326802281000 |
+-----------+-----------------+------------------+---------------+
| 6         | 7               | 4                | 1326802941000 |
+-----------+-----------------+------------------+---------------+
| 7         | 7               | 1                | 1326814161000 |
+-----------+-----------------+------------------+---------------+
| 8         | 6               | 2                | 1328026700000 |
+-----------+-----------------+------------------+---------------+

equipment

+--------------+------------------+
| equipment_id | equipment_string |
+--------------+------------------+
| 1            | Microdoser       |
+--------------+------------------+
| 2            | Monoblock        |
+--------------+------------------+
| 3            | Valve Magnet     |
+--------------+------------------+
| 4            | Checkweigher     |
+--------------+------------------+
| 5            | Microleak        |
+--------------+------------------+
| 6            | Capper           |
+--------------+------------------+

Query

SELECT equipment_string AS eqpt, COUNT(reject_id) AS cnt
FROM reject_data
RIGHT OUTER JOIN equipment ON (reject_equipment = equipment_id) 
WHERE reject_location IN (1,2,7) AND equipment_id IN (1,2,3,4,5,6) AND reject_time BETWEEN 1329479810000 AND 1329483410000
GROUP BY equipment_id
ORDER BY cnt DESC

Question

How do I alter my query so that it also returns equipment that have zero counts? Really stuck 🙁

Thank you for any help.

Note: Dynamic variable populates the IN normally.

  • 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-29T22:30:09+00:00Added an answer on May 29, 2026 at 10:30 pm

    The WHERE clause does the filtering after the JOIN, so it will filter out any records where the JOIN failed (since reject_location IN (1,2,7) won’t be true for those). You need to move those restrictions to the ON clause:

    SELECT equipment_string AS eqpt, COUNT(reject_id) AS cnt
    FROM reject_data
    RIGHT OUTER JOIN equipment
           ON reject_equipment = equipment_id
          AND reject_location IN (1,2,7)
          AND reject_time BETWEEN 1329479810000 AND 1329483410000
    WHERE equipment_id IN (1,2,3,4,5,6)
    GROUP BY equipment_id
    ORDER BY cnt DESC
    

    In this case, another approach, which you might find more clear, is to use a subquery rather than a join:

    SELECT equipment_string AS eqpt,
           ( SELECT COUNT(1)
               FROM reject_data
              WHERE reject_equipment = equipment_id
                AND reject_location IN (1,2,7)
                AND reject_time BETWEEN 1329479810000 AND 1329483410000
           ) AS cnt
      FROM equipment
     WHERE equipment_id IN (1,2,3,4,5,6)
     ORDER BY cnt DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to bulid a table layouts like this.how? alt text http://privateevent.co.uk/underground/img/gallery/19_1236343602.png
I am importing massive amounts of data from Excel that have various table layouts.
I know there are various good arguments preferring CSS positioning over table-based layouts. What
I'm trying to put a table inside a div for easy layouts. But as
I have some legacy layouts with nested tables. I'd like the parent table's <td>
Recently, I like using CSS-Table Layouts more and more. When I had another issue
So right now one of my layouts has a table image set as a
I have one big LinearLayout(vertical)(outer table) and three small linear layouts(horizontal)(one for each row).
I like to follow standards and use table-less div based layouts. However using tables
I've got a nice table populated with data, with custom-designed cell layouts. Currently, tapping

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.