Getting Records Returned When Criteria Doesn't Match (Using One Query)

I have made two queries which I would like to fold into one query if possible. The first query includes all grp_id's. The second query updates grp_id's with an (active) member count. This second query has criteria in it that grabs only grp_id's that have active members. This would be similar to say, for example, a left join situation where everything is returned from table A and only those matching from table B.
The problem is that if I put these together, they have to be linked by grp_id, so obvioulsy, if I put these queries together, the only grp_id's I will get back are the ones that have active members in them, but as I mentioned, I need all grp_id's to be shown regardless of any active membership.
So, here is the code that doesn't work to give a better idea of what I want.
select g00.grp_id,
count(m06.subs_ssn)
from gmaster g00
join m_elig m06 on
g00.grp_id = m06.grp_id
and m06.eff_date < sysdate
and m06.exp_date > sysdate
and m06.stat_code = 'ACTIVE'
group by g00.grp_id
Again, this will only give me counts for grp_id's with active members in them, whereas I want all grp_id's shown and those grp_id's without active members to have a zero next to the count..
m06 gives the member data and g00 gives the grp_id data. The m06 eff_date and exp_date and stat_code as shown above determine active members..
Thanks for any suggestions..

I don't know why its not working. I did make an error in the intial posting of the data which was to put NOAM in grpid 'C'. I thought this might be my error, but I corrected it and am still getting the same results.
I have repasted the DDL statements, the query I'm using, the results and also the data as it shows when I query the two tables. (my query is based off the tables created using the posted DDL).
I also posted QUERY B. Which shows that the removal of the eff_dt and exp_dt criteria allows grp_id to be posted in the results, obviously showing 1 record as I no longer am defining an ACTIVE member by having criteria as posted in QUERY A.
Is my LEFT OUTER JOIN statement written correctly?
Also of note: I could not insert the data without the apostrophes in the dates. It gave me an error (Column not allowed here). Using the apostrophes eliminates this message and allows the data insertion. At least for now its not causing an issue as the data shows correct when I query it based a simple query of the dates.
Using PL/SQL don't know if that makes a difference..?
=======================================================
DATA IN TBL: GRP_ID:
1     A
2     B
3     C
4     D
DATA IN TBL: MBR
1     MARK     A     Y     1/1/2011     7/1/2011
2     MARK     A     Y     7/1/2011     1/1/2012
3     MARTY     A     Y     1/1/2011     7/1/2011
4     MARTY     A     Y     7/1/2011     1/1/2012
5     FRANK     B     Y     1/1/2011     7/1/2011
6     FRANK     B     Y     7/1/2011     1/1/2012
7     MARY     B     Y     1/1/2011     7/1/2011
8     MARY     B     Y     7/1/2011     1/1/2012
9     JEAN     C     Y     1/1/2011     7/1/2011
10     JEAN     C     Y     7/1/2011     1/1/2012
11     NOAM     D     Y     1/1/2011     7/1/2011
As you can see, Mark, Marty should have 1 active record in grp_id 'A' (total 2), Frank and Mary should have 1 active record each 'B' (total 2), Jean should have 1 active record in 'C' grp_id, total 1) and Noam should have no active records.
====================================
QUERY A:
SELECT
g00.grpid,
count(m00.grpid) mbr_count
FROM
grp_id g00
left outer join mbr m00 on
g00.grpid = m00.grpid
WHERE
m00.eff_dt < sysdate
AND
m00.exp_dt > sysdate
GROUP BY
g00.grpid
QUERY A RESULTS
1     A     2
2     B     2
3     C     1
QUERY B
SELECT
g00.grpid,
count(m00.grpid) mbr_count
FROM
grp_id g00
left outer join mbr m00 on
g00.grpid = m00.grpid
GROUP BY
g00.grpid
QUERY B RESULTS:
1     A     4
2     B     4
3     C     2
4     D     1
=================================================
DDL STATEMENTS
create table mbr (mbr_name varchar(10), grpid varchar(1), stat varchar(1), eff_dt date, exp_dt date)
insert into mbr values ('MARK', 'A','Y', '01-jan-2011', '01-jul-2011')
insert into mbr values ('MARK', 'A','Y','01-jul-2011', '01-jan-2012')
insert into mbr values ('MARTY', 'A','Y','01-jan-2011', '01-jul-2011')
insert into mbr values ('MARTY', 'A','Y', '01-jul-2011', '01-jan-2012')
insert into mbr values ('FRANK', 'B','Y','01-jan-2011', '01-jul-2011')
insert into mbr values ('FRANK', 'B','Y','01-jul-2011', '01-jan-2012')
insert into mbr values ('MARY', 'B','Y','01-jan-2011', '01-jul-2011')
insert into mbr values ('MARY', 'B','Y','01-jul-2011', '01-jan-2012')
insert into mbr values ('JEAN', 'C','Y','01-jan-2011', '01-jul-2011')
insert into mbr values ('JEAN', 'C','Y','01-jul-2011', '01-jan-2012')
insert into mbr values ('NOAM', 'D','Y','01-jan-2011', '01-jul-2011')
commit

Similar Messages

  • How to clear GR/IR account when criteria is not matching

    Hi All,
    I have issue in clearing GR/IR account done by F.13.  Criteria field XREF3 in Criteria 3 given is not matching in WE and RE, so I cannot clear, this happend to once particular GR/IR only.
    So how to clear this GR/IR when Criteria is not matching.
    Syam

    Hi,
    You can clear it manually using F-03. In that T-Code it is a manual clearing and not automatic clearing...so you can select any line items you want to clear, only thing is that their balance should be Zero.
    Regards,
    SAPFICO

  • Since upgrading to Mavericks I am finding that I am lucky to get 2 hours (when connected to WiFi) of use from my macbook Pro.

    Since upgrading to Mavericks I am finding that I am lucky to get 2 hours (when connected to WiFi) of use from my Macbook Pro.  I have turned off Bluetooth ( which was not an issue previously), uninstalled Chrome, again not an issue before I upgraded, and have not seen any improvement.
    I was using an older OS system (Snow Leopard) on my 2010 Macbook Pro.  I am wondering now if the upgrade was an unwise move?

    jbuckworth,
    which apps do you run under battery power? Are any of them identified as “apps using significant energy” when you click on the battery icon in the menu bar? If you have a 15-inch or 17-inch model, are your apps using the discrete GPU (which consumes more power than the integrated GPU)?
    How many charge cycles has your battery accumulated?
    How long have you had Mavericks installed? Is Spotlight still reïndexing your boot drive? (It does that whenever your OS is upgraded, because so many files change in an OS upgrade.)

  • Keep getting this error when ever I try to use the CC_2014

    keep getting this error when ever I try to use the CC_2014 InDesign
    Unable to launch Adobe InDesign as you do not have sufficient permissions to access the preferences folders. Ensure that you have appropriate permissions and then restart Adobe InDesign.
    Also have Ai quit out on me in the CC_2014.
    This is very frustration since I use these the most

    For MAC try to give permissions to Adobe Indesign Folder:
    Users/[user]/Library/Caches/Adobe InDesign
    Users/[user]/Library/Preferences/Adobe InDesign
    Access hidden user library files | Mac OS 10.7 and later
    For Windows try to give permissions to Adobe Indesign Folder:
    C:\Users\[username]\AppData\Roaming\Adobe\InDesign
    C:\Users\[username]\AppData\Roaming\Adobe\InDesign
    Also you can try logging in under a local administrator account as suggested by jeff.

  • Why am I getting an error when I place two OAM files one after the other in different pages?

    Why am I getting an error when I place two OAM files one after the other in different pages? They do not load or play correctly.  They are both configured to play automatically with a .125 second delay and both have a white rectangle "poster" over for a hidden effect.

    Thanks for the idea, Scott! I initially tried your idea, but my OAM files were still not loading correctly.  I tried other combinations of OAM files, and it seems to work fine.
    Back to my original OAM files: I made sure that my elements in my Edge Animate project had different names. I originally copied parts of some elements from one to another, and I think it was confusing to DPS to read it. 

  • Getting null returned when working with Linked Lists

    Ok, i'm having the same problem with a couple of methods that deal with linked lists, and i was hoping someone could lend me a hand. First off, the specifications for one of the methods:
    An iterative procedure smallElements
    PARAMETERS: a ListItem reference, ls
    an integer n
    RETURN VALUE: a new list identical to the given list, except
    that it contains no occurrences of numbers greater than n.
    for example, given input list ( 3 2 6 3 4 ) and 3,
    the return value would be the list ( 3 2 3 )
    And here is my code:
    ListItem smallElements(ListItem ls, int n){
    ListItem small = null;
    ListItem result = small;
    if(ls == null)
    return null;
    else{
    while(ls!=null){
         if(ls.number <=n){
         result = new ListItem(ls.number, null );
         result = result.next;
         ls = ls.next;
    return small;
    Like the topic says, i keep getting null returned as a value. I have tried setting small= new ListItem(ls.number, null), and that actually returns the correct list, except that the first number is repeated twice. I would greatly appreciate any assistance.

    I am not sure I understand your code. What exactly are those ListItems? It seems to me that you are dealing with single List elements, while the specification says that you are supposed to return a List.
    But the main error is that you have two ListItem objects there, which seems to fill the same purpose - only that you use one, and return the other. 'small', which is the one you return, never get set to anything else than null.
    I think you should do something like this: make a new, empty list to return
    for element in parameterlist
        if number is smaller than n
            add this element to returnlist
    return returnlist

  • Why the oldest recorded track get recorded again when making new track?

    1. I play my guitar and record it (track1)
    2. I play track1 and recording my vocal
    3. The track1 get recorded again on my vocal track
    How to set off that? So i dont have double sound of the oldest track on the new track

    Kaibe008 wrote:
    3. The track1 get recorded again on my vocal track
    How to set off that?
    use headphones

  • The kernel the system is running doesn't match the one installed

    I've been trying to install Arch to a new desktop I've built. The wireless card(TP-link wn725n v2) requires a driver that I've downloaded, and have been trying to get on the system. I finally decided to install Arch to a flash drive, install the driver to the flash drive, and then install Arch to the desktop. When installing the driver to the desktop, I don't run into any problems. When I tried installing on the USB, I got an error message. I did a quick google search and found I forgot to install the linux headers. Then another problem showed its face.
    "make ARCH=i386 CROSS_COMPILE= -C /lib/modules/3.12.3-1-ARCH/build M=/home/Test/Driver/rtl8188eu-master  modules
    make[1]: *** /lib/modules/3.12.3-1-ARCH/build: No such file or directory.  Stop.
    Makefile:146: recipe for target 'modules' failed
    make: *** [modules] Error 2"
    I looked around more, and I think I've located the source of the error.
    When I type in 'uname -r'
    I get: '3.12.3-1-ARCH'
    When I type in 'pacman -Q linux'
    I get: 'linux 3.12.6-1'
    I'm not sure where to go from here. Any ideas?
    Last edited by ryanfahy314 (2013-12-28 17:16:48)

    Ryan, could you also revise your title to more specifically identify the problem you are facing.  I suspect an update and reboot will fix the problem, as I'd agree with your diagnosis: the kernel running does not match the one installed - but in case we're wrong, the title-worthy component of the problem would relate to failure to build rtl8188eu driver.
    Last edited by Trilby (2013-12-28 12:43:48)

  • Artwork Doesn't Match on One iPod but Does on The Other

    I have two iPods 60GB and 80GB both fifth generations and I'm using iTune 7.1.1
    My problem is that some artwork on my 60GB iPod doesn't match the song "not the correct artwork", but on iTune and on the 80GB iPod all the artwork match!!!!!!!!!!!
    PLEEEEEEEEEEEEEEEEEEEEEEEAAAAAAAAAAAAAAAAAAAAAAAAAASE HEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEELP
    Badr
    HP Windows XP Pro

    1. Connect your iPod
    2. Disable "Display album artwork" in iPod>Music tab and click Apply.
    3. Syncronise the iPod with iTunes.
    4. Re-enable "Display album artwork" in iPod>Music tab and click Apply.
    5. Syncronise the iPod again.

  • To get list of Structure, CKF and RKF where used in query

    Hi All,
    We are going to migrate the queries from BW.3.5 to BI 7.0.
    Our aim  is to get list of Structure, CKF and RKF that are being used in the Info provider along with Queries of these Structure ,RKF's and CKF' s .Is there any way
    to get the where used in query.
    Thanks,
    Mohan

    It's been discussed so many times: Check these forums>>
    http://scn.sap.com/thread/2029042
    BEx metadata tables - how to list Query/Chars/KFs
    Rgds..
    Shambhu

  • Previous DB Record Returned When Last Search Not Found

    I have a problem that nobody seems to know about or perhaps I'm just not seeing. Anyway, I put together a simple SQL manager javabean and other than my current issue, it's worked great. Here is my problem:
    SELECT * FROM site_mimetypes WHERE extension = 'PROPERTIES'
    SELECT * FROM site_mimetypes WHERE extension = 'DOC'
    SELECT * FROM site_mimetypes WHERE extension = 'NODICE'These queries run as they should at the db command-line:
    - first query returns empty
    - second query returns a record that matchs
    - third query returns empty
    Now, if I run this through the sql javabean, the third query returns the results of the second query. I've also tried using the sql "LIKE" command to no avail. This happens very consistantly. Whats funny though is if for example the extension I'm looking for doesn't exist at all in any form, meaning say I'm searching for the string "EXE", it will return properly as empty because there aren't any records that start with the letter "E". Now as I understood it, isn't the "=" operator supposed to find an exact match. It certainly works a 100 percent of the time during the first query and always when done from the db command-line. I'm using MySQL, Tomcat 5.0, JDK 1.5, Connector/J 3.0.... Below I'll post my sql javabean and below that, I'll post my simple JSP file that calls that javabean:
    JAVABEAN:
    package sql;
    import java.sql.*;
    import java.util.*;
    import java.io.*;
    public class SQLManager {
         private String SQL_URL = new String();
         private String SQL_USER = new String();
         private String SQL_PASS = new String();
         private static String SQL_DRIVER = new String();
         private String SQL_RESULT = new String();
         private String PROP_PATH = "C:\\Program Files\\Apache Software Foundation\\Tomcat 5.0\\webapps\\dam\\WEB-INF\\classes\\sql\\";
         private String PROP_FILE = "database.properties";
         public SQLManager() { }
         public String getResult() { return this.SQL_RESULT; }
         public void executeQuery(String statement, int column) throws SQLException {
              try {
                        retrieveProperties(PROP_PATH + PROP_FILE);
                      Class.forName(SQL_DRIVER);
                          Connection conn = DriverManager.getConnection(SQL_URL, SQL_USER, SQL_PASS);
                        Statement stat = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                        ResultSet rs = stat.executeQuery(statement);
                        while(rs.next()) {
                             this.SQL_RESULT = rs.getString(column);
                        rs.close();
                        stat.close();
                        conn.close();          
              } catch(ClassNotFoundException ce) { }
                catch(SQLException se) { }
                catch(IOException ie) { }
         public void retrieveProperties(String filename) throws IOException {
              Properties props = new Properties();
              FileInputStream in = new FileInputStream(filename);
              props.load(in);
              in.close();
              this.SQL_DRIVER = props.getProperty("jdbc.drivers");
              this.SQL_URL = props.getProperty("jdbc.url");
              this.SQL_USER = props.getProperty("jdbc.username");
              this.SQL_PASS = props.getProperty("jdbc.password");
    }JSP
    <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
    <head>
    <title>JSP Test</title>
    <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
    </head>
    <jsp:useBean class="sql.SQLManager" id="sql" scope="page">
    </jsp:useBean>
    <body>
    <%
    sql.executeQuery("SELECT * FROM site_mimetypes WHERE extension = 'VOODOO';", 2);
    sql.executeQuery("SELECT * FROM site_mimetypes WHERE extension = 'DOC';", 2);
    sql.executeQuery("SELECT * FROM site_mimetypes WHERE extension = 'FILE';", 2);
    %>
    <%= sql.getResult() %>
    </body>
    </html>

    My guess is that the third query is throwing an exception and the previous result set does not get cleared. To test this theory simply change the execution order of the queries. Also I'd rewrite the executeQuery() method as follows as it guarantees resource cleanup in the event of an exception and will display the exception to the console if one does get triggered:
    public void executeQuery(String statement, int column) throws SQLException
      try
        retrieveProperties(PROP_PATH + PROP_FILE);
        Class.forName(SQL_DRIVER);
        Connection conn = DriverManager.getConnection(SQL_URL, SQL_USER, SQL_PASS);
        Statement stat = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
        ResultSet rs = stat.executeQuery(statement);
        while(rs.next())
          this.SQL_RESULT = rs.getString(column);
      catch(Throwable th)
        th.printStackTrace();
      finally
        try
          if (rs != null)
           rs.close();
        catch(SQLException sqe)
        try
          if (stat != null)
           stat.close();
        catch(SQLException sqe)
        try
          if (conn != null)
           conn.close();
        catch(SQLException sqe)
    }

  • Duplicate records returned when details come from 2 different tables

    I believe this should be a trivial case, but after days and days of experimenting, I can't get it. I'm creating a report of customers' transactions. The customer table links to a transaction header table (default join type). There are 2 tables which link to the transaction header, one for normal transaction line items, one for refunds. There is no correlation between the line items in the transaction table and those in the refund table, and they may or may not share a header. I have linked these two tables to the transaction header with left-outer-joins. What I want in the dataset, for a given transaction header, are all normal line items followed by all the refund line items (or vice versa). What I get, however, is a record for each combination of transaction details and refund details, whenever they share a common header. So, for example, if I have transaction line items 1, 2, 3, and 4 for a given header, plus refund lines A and B for the same header (as might happen if a customer returned 2 products at the same time he bought 4), what I want is a data set of 1,2,3,4,A,B. Instead, what I get is 1A,1B,2A,2B,3A,3B,4A,4B.
    How can I get the result I need? Is this simply a join issue, or must I weed out the duplication using complex formula scripts? Or a subreport? Or something else?
    thanks.
    John

    Subreport would solve this problem but it sub-report take a long time export. Does anyone know how to integrate subreport without suffering the performance lost?
    My report have two subreport and everytime I tried to export the value it take ages to export. My database is only about 20k items and it take almost 10 min to export.
    Does any one know how to make this process faster?

  • I keep getting an error when attempting to start Match.  It looks like it uploaded all my music, but it won't complete the task without an error.

    Is anyone else having problems getting started with Match?  I keep getting an error message and
    then it requests I close down iTunes.

    Hi,
    Try holding shift key whilst signing out of match then close iTunes. Reboot computer then launch iTunes. Now sign back into iTunes Store and activate iTunes Match. You will be asked to add this computer, do so.
    You should add iCloud status to song view. Go to menu > view > view options and tick box. This will tell you what has been matched, uploaded, purchased, duplicate, inelligible or waiting. If match process is failing to complete, you should delete "waiting" tracks but do not move to trash. Those tracks may include some that match does not like and is preventing process from completing.
    Once process has complete, try adding those tracks again, a small number at a time.
    Jim

  • How to get the return when use this function ----- getUsersInGroup()

    how do we assign list of nodes that getUsersInGroup() returns? And how do we get the result of the returns? And where is the groups and users config files? I am attempting notifications to all users in a group. Thank you!!

    Why do you want to do that, you cannot attach a VO which is not present in the AM. Can you elaborate on your requirement.

  • HT201269 how to transfer content via icloud when OS doesn't match

    can't download to new iphone because backup OS is more current then new iphone 5S

    Set up your iPhone as a new phone to get through the activation process. Then, go to Settings>General>Reset>Erase all content and settings. Once it restarts, restore from your iCloud backup.
    ~Lyssa

Maybe you are looking for

  • Searching file from directory located at http path.

    Hi All, I have made the program to search for a file in a directory and its subdirectories. This is working fine when my directory is located on local machine. But if the same directory is placed in HTTP path, the code fails to search a directory. Do

  • Can ypou move songs from one ipod to another?

    Is there a way to move songs from one way to another, if so can you tell me.

  • My Ipod Touch will not sync to I-tunes

    I am using I-tunes 12.1.1.4 65 bit on Windows and for some reason it will no longer sync with my Ipod Touch using 6.1.6 firmware. I have re-installed Itunes, re-set my Ipod Touch, everything. I check for updates and everything is appearing up to date

  • Playlist shuffling problems.

    When hit shuffle on playlists or even all songs its skips over a lot of songs. The song count will go from 50 to 12 making it impossible to listen to an entire playlist on shuffle. Is there a way to fix this or do I have to live with this until the n

  • Exception handling raised in named subprograms

    Hi, I would like to call three procedures from a when button pressed trigger and deal with them individually. I tried naming the exception in the procedure, not to handle it there, and get it to propagate in the calling trigger. Here is the code for