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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:41:41+00:00 2026-05-24T06:41:41+00:00

Table foobar is, for clarity, structured and has data as follows: id, action_dt, status_id

  • 0

Table foobar is, for clarity, structured and has data as follows:

id, action_dt, status_id
1, '02-JUL-10', 'x'
1, '02-JUL-10', '2'
1, '02-JUL-10', NULL
2, '02-JUL-10', 'a'
2, '02-JUL-10', 'b'
3, '02-JUL-10', 'k'
3, '02-JUL-10', NULL
3, '03-JUL-10', 'k'
3, '03-JUL-10', NULL

I need a query that gets IDs such that for each ID a NULL value and a NOT NULL value exists per day. So, in the example dataset above, the query needs to return:

'02-JUL-10', 1
'02-JUL-10', 3
'03-JUL-10', 3

Yes, it can be done using something like:

SELECT
    nulls.action_dt
    , nulls.id 

FROM        (SELECT 
                action_dt
                , id 
            FROM        foobar 
            WHERE       status_id IS NULL
            GROUP BY    action_dt)   nulls

INNER JOIN (SELECT
                action_dt
                , id
            FROM        foobar 
            WHERE       status_id IS NOT NULL
            GROUP BY    action_dt)    non_nulls     ON nulls.action_dt = non_nulls.action_dt 
                                                        AND nulls.id = non_nulls.id



but as you can see, among other things, two subqueries and another iteration for the join…

The query I’ve been working on and have hopes for is of the form:

SELECT
    action_dt
    , id
FROM
    foobar
GROUP BY
    action_dt
    , id
    , CASE WHEN status_id IS NOT NULL THEN 1 ELSE 0 END
HAVING
    COUNT(prim_card_nb) > 1

but it doesn’t quite return what I need (as you know, the HAVING clause applies to the underlying data that is being queried). Any ideas?

After all this, it seems a solution would be to have the above query in a subquery and filter it down that way, such as:

SELECT
    action_dt
    , id
FROM        (SELECT
                action_dt
                , id
            FROM
                foobar
            GROUP BY
                action_dt
                , id
                , CASE WHEN status_id IS NOT NULL THEN 1 ELSE 0 END
            ) repeat_ids_per_day
GROUP BY
    action_dt
    , id
HAVING
    COUNT(id) > 1

but I feel it can be better…

  • 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-24T06:41:41+00:00Added an answer on May 24, 2026 at 6:41 am

    Your idea is sound: in such a case you don’t need a subquery, an aggregate is sufficient and should be more efficient. This should work:

    SQL> SELECT action_dt, id
      2    FROM foobar
      3   GROUP BY action_dt, ID
      4  HAVING COUNT(DISTINCT CASE WHEN status_id IS NULL THEN 1 ELSE 0 END) > 1;
    
    ACTION_DT         ID
    --------- ----------
    02-JUL-10          1
    02-JUL-10          3
    03-JUL-10          3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have SQL table that has a varchar(8) column that occasionally has binary data
For example, foobar should hash to something like 3456. My hash table array has
I have a table full of tabular data. I need to find the index
I have problems to query my data. Here are my tables: CREATE TABLE `A`
I am trying to navigate a table row that has been clicked, to extract
Does anyone know the proper way to query azure table storage for a null
I have a table that looks somewhat like this: CREATE TABLE foobar ( id
I am creating table like this: CREATE TABLE foobar (id uniqueidentifier, foo text, bar
Table has the following info: date |vendor|sales|percent| -------------------------- 2009-03-03| 10 |13.50| 1.30 | 2009-03-10|
table 1(ob): name,address table 2(address): dname,addr I need to update ob.address with address.addr when

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.