Writing single query with conflicting WHERE statements

How do I run the following as a single query that will result in a column that pertains to the first block of code and then another column that pertains to the 2nd block of code? The issue is that I need 2 different WHERE statements. So the final output will be patient_id, complete, incomplete.
SELECT patient_id, COUNT(*) AS complete
FROM STATUS
WHERE status = 1
GROUP BY patient_id
ORDER BY patient_id;
SELECT patient_id, COUNT(*) AS incomplete
FROM STATUS
WHERE status = 2
GROUP BY patient_id
ORDER BY patient_id;
Thanks!

Hi,
apex wrote:
Thanks for all of the help.
I would like to add another column with decile and am struggling as to how to do it. Since I can't reference something in a calculation in the same step, I think I will need a 3rd nesting, but what I haven't figured out is how to get the number of subjects whose ratio is less than that subject's ratio. Right: you can't assign an alias (such as complete or ratio) to a calculated column and use that alias in the same sub-query.
If the calculation isn't very complicated, then you might find it simpler just to repeat the calculation. For example, I think this is what you want:
WITH     got_complete     AS
     SELECT    patient_id
     ,        COUNT ( CASE WHEN status = 1 THEN 1 END )     AS complete
     ,       COUNT ( CASE WHEN status = 2 THEN 1 END )      AS incomplete
     FROM        pt_status
     WHERE        status IN (1,2)
     GROUP BY  patient_id
SELECT       patient_id, complete, incomplete
,                                complete / (complete + incomplete)     AS Ratio
,       RANK () OVER ( ORDER BY  complete / (complete + incomplete) ) - 1
                                                    AS decile
FROM      got_complete
ORDER BY  complete
,            incomplete     DESC
;RANK numbers rows 1, 2, 3, ... If I understand your requirements, you want the numbering to start with 0 (meaning "there are 0 other patients with a lower ratio"), so that's why I subtracted 1.
Depending how you want to handle ties, you may need to add some tie-breaker expressions to the analytic ORDER BY clause, and/or use ROW_NUMBER instead of RANK.
Here, I used the calculation "complete / (complete + incomplete)" in the ratio column, then repeated it in the decile column.
I you want, you can add another sub-query, called got_ratio, which would add the ratio column, but do nothing about the decile column. Then, in the main query, you could use RANK as shown above (or, as you suggested, a scalar sub-query referencing got_ratio) to get the number of other pateient_ids with lower ratios.
On the other hand, you could do this whole job without any sub-queries, using AVG as I did earlier, and then repeating that same AVG expression in the ORDER BY clause for RANK. Aggregate functions are computed before analytic fucntions, so the analytic RANK can referenece the aggregate AVG.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data. Include examples of decile ties (2 or more patients with the same ratio).
Explain, using specific examples, how you get those results from that data.

Similar Messages

  • Dynamic select query with dynamic where condition

    Hi all,
    I want to use the dynamic select query with dynamic where condition. For that I used the below code but I am getting dump when using this code.
    Please advice, if there is any other way to achieve this requirement.
    Thanks,
    Sanket Sethi
    Code***************
    PARAMETERS: p_tabnam      TYPE tabname,
                p_selfl1      TYPE edpline,
                p_value       TYPE edpline,
                p_where1      TYPE edpline .
    DATA: lt_where    TYPE TABLE OF edpline,
          lt_sel_list TYPE TABLE OF edpline,
          l_wa_name   TYPE string,
          ls_where    TYPE edpline,
          l_having    TYPE string,
          dref        TYPE REF TO data,
          itab_type   TYPE REF TO cl_abap_tabledescr,
          struct_type TYPE REF TO cl_abap_structdescr,
          elem_type   TYPE REF TO cl_abap_elemdescr,
          comp_tab    TYPE cl_abap_structdescr=>component_table,
          comp_fld    TYPE cl_abap_structdescr=>component.
    TYPES: f_count TYPE i.
    FIELD-SYMBOLS : <lt_outtab> TYPE ANY TABLE,
    *                <ls_outtab> TYPE ANY,
                    <l_fld> TYPE ANY.
    struct_type ?= cl_abap_typedescr=>describe_by_name( p_tabnam ).
    elem_type   ?= cl_abap_elemdescr=>describe_by_name( 'F_COUNT' ).
    comp_tab = struct_type->get_components( ).
    comp_fld-name = 'F_COUNT'.
    comp_fld-type = elem_type.
    APPEND comp_fld TO comp_tab.
    struct_type = cl_abap_structdescr=>create( comp_tab ).
    itab_type   = cl_abap_tabledescr=>create( struct_type ).
    l_wa_name = 'l_WA'.
    CREATE DATA dref TYPE HANDLE itab_type.
    ASSIGN dref->* TO <lt_outtab>.
    *CREATE DATA dref TYPE HANDLE struct_type.
    *ASSIGN dref->* TO <ls_outtab>.
    * Creation of the selection fields
    APPEND p_selfl1 TO lt_sel_list.
    APPEND 'COUNT(*) AS F_COUNT' TO lt_sel_list.
    ** Creation of the "where" clause
    *CONCATENATE p_selfl1 '= '' p_value ''.'
    *            INTO ls_where
    *            SEPARATED BY space.
    *APPEND ls_where TO lt_where.
    * Creation of the "where" clause
    APPEND p_where1 TO lt_where.
    * Creation of the "having" clause
    l_having = 'count(*) >= 1'.
    * THE dynamic select
    SELECT          (lt_sel_list)
           FROM     (p_tabnam)
           INTO CORRESPONDING FIELDS OF TABLE <lt_outtab>.
    *       WHERE    (lt_where).

    Hi Sanket,
    The above given logic of mine works for you, put the code in the If condition and try-
    just like below:
    IF NOT P_EBELN IS INITIAL.
    lt_where = '& = ''&'' '.
    REPLACE '&' WITH p_ebeln INTO lt_where.
    REPLACE '&' WITH field_value INTO lt_where.
    SELECT (lt_sel_list) INTO CORRESPONDING FIELDS OF TABLE <lt_outtab>
    FROM (p_tabnam)
    WHERE (lt_where).
    ENDIF.
    thanks\
    Mahesh

  • Single SQl Query with different where conditions

    Experts,
    I have a requirement to design a report. Here are the details
    I have Report table layout
    Profit center Gross sales (This Year) Gross Sales (Last Year) % change Year of Year
    The Report has a selection of entering the Start Date.
    I have a single table in oracle which has profit center and Gross Sales Values on daily basis.
    I want to write a single sql query to calculate both Gross Sales current year and Gross Sales Last Year. I can calculate Gross Sales Current Year by putting the where condition for start date = Current Year Date which i pass through report. I want to calculate the Gross Sales Last Year in the Same query by putting the different where condition i.e start date = Last Year date based on the date input.
    I dont know how to put two where conditions in single query for two different columns.
    Any help will be appreciated.
    Thanks in advance
    Regards
    Santosh

    instead of changing your where clause couldn't you just determine the yearly totals from your table and then use the lag statement to get last years total?
    something like this?
    I just made up 10,000 days worth of sales and called it fake table it is supposed to represent a variant of the table you were describing as your base table.
    with fake_table as
    ( select trunc(sysdate + level) the_day,
    level daily_gross_sales
    from dual
    connect by level < 10001
    select yr, year_gross_sale, lag(year_gross_sale) over (order by yr) prev_year_gross_sale,
    (year_gross_sale - lag(year_gross_sale) over (order by yr))/year_gross_sale * 100 percent_change
    from
    (select distinct yr, year_gross_sale from
    select the_day,
    daily_gross_sales,
    extract(year from the_day) yr,
    extract(year from add_months(the_day,12)) next_yr,
    sum(daily_gross_sales) over (partition by extract(year from the_day)) year_gross_sale
    from fake_table
    order by yr
    )

  • Single Query with multiple fiscal variants / fiscal period

    Experts,
    Currently we have two different queries 1) for US and 2) for Mexico.
    Both the queries are hard-coded with respective company codes and different fiscal variants. We have i step =1 variable, so in both query we have respective fiscal period by default in variable screen.  The user can decide to run the query for current fiscal period or manually overwrite it for past few fiscal periods.
    Now, we want to consolidate two queries into a single one and behind the scene depending on company code entered by user we want the query to run for default period AND we also want user to have liberty to change it for different fiscal periods (similar to istep 1 variable) which is hard coded for each query. Please advice how to proceed?
    Thanks!

    Hi Durgesh,
    I agree with part 1- we can let user select his company code, but my challenge is pre-populate or get the default fiscal period for different company codes.
    2) You can keep rest of the things as it is, because you will be populating the default period value and if user want he can select the required value manually.
    (Alok) =  So if user runs report in Nov'2011 = the US fiscal period is 002/2012; but for Mexico it might be 011/2011 - so is there any way where we can give this value in prompt screen and at the same time not let user remember these values...
    Since with single query and without hardcoding how to determine the current fiscal period for different company codes?

  • DocumentClient query with Int64 where clause is incorrect when converted and sent to Azure

    The code below constructs a query with a lambda expression involving an Int64. When the query is converted and sent to Azure, it is incorrect. I captured the request to Azure using Fiddler for the example below, and the body contained:
    {"query":"SELECT * FROM root WHERE (root.car.id = 1.01036229983142E+16) "}
    Notice the constant does not match that of the code. Is this a bug in Azure DocumentDB library? If so, where can I submit a bug?
    long carId = 10103622998314238;
    IQueryable<MyDocument> query = documentClient.CreateDocumentQuery<MyDocument>("<collectionLinkGoesHere>", new FeedOptions { MaxItemCount = 1 });
    query = query.Where((MyDocument d) => d.Car.Id == carId);
    await query.AsDocumentQuery().ExecuteNextAsync<T>();

    @kurifodo1, DocumentDB follows the JSON standard for numbers, which is http://en.wikipedia.org/wiki/IEEE_754 notation. So any long integer gets serialized to a double stored as IEE754, and will lose some precision. While this isn't the most intuitive behavior,
    it's important in order to be compliant with other tools and platforms that speak JSON.
    If you'd like to just perform equality queries, consider storing this as a string. If you'd like to perform range queries, consider breaking up the number into two parts (high and low), similar to the BigInteger structure in C#.
    Hope this helps.

  • How to write the select query with complex where condition

    Hi all,
    Can u help me in writing  following select query.
    select * from zu1cd_corr where time_stamp between firstday and lastday .
    In the above query time_stamp contains the date and time.
    where as firstday and lastday contains the dates.
    I need to compare the date in the time_stamp with the firstday and lastday.
    But time_stamp contains the time also and it is char of 14 characters length.

    Hi,
    If that is the case u can do as advait specified....
    if the firstday and secondday are select-options then declare two more variables having 14 character length and then concatenate '000000' to firstday variable and '240000' to last day variable and then write ur query.
    CLEAR : lv_firstday,
                 lv_lastday.
    concatenate firstday '000000' to lv_firstday.
    concatenate lastday '240000' to lv_lastday.
    ranges : r_Date for zu1cd_corr-time_stamp.
    r_date-sign = 'I'.
    r_date-option = 'BT'.
    r_Date-low = lv_firstday.
    r_Date-high = lv_lastday.
    append r_date.
    select * from zu1cd_corr  into table it_zu1cd_corr where time_stamp in  r_Date.
    I hope it helps.
    Regards,
    Nagaraj

  • Need help with writing a query with dynamic FROM clause

    Hi Folks,
    I need help with an query that should generate the "FROM" clause dynamically.
    My main query is as follows
    select DT_SKEY, count(*)
    from *???*
    where DT_SKEY between 20110601 and 20110719
    group by DT_SKEY
    having count(*) = 0
    order by 1; The "from" clause of the above query should be generated as below
    select 'Schema_Name'||'.'||TABLE_NAME
    from dba_tables
    where OWNER = 'Schema_Name'Simply sticking the later query in the first query does not work.
    Any pointers will be appreciated.
    Thanks
    rogers42

    Hi,
    rogers42 wrote:
    Hi Folks,
    I need help with an query that should generate the "FROM" clause dynamically.
    My main query is as follows
    select DT_SKEY, count(*)
    from *???*
    where DT_SKEY between 20110601 and 20110719
    group by DT_SKEY
    having count(*) = 0
    order by 1; The "from" clause of the above query should be generated as below
    select 'Schema_Name'||'.'||TABLE_NAME
    from dba_tables
    where OWNER = 'Schema_Name'
    Remember that anything inside quotes is case-sensitive. Is the owner really "Schema_Name" with a capital S and a capital N, and 8 lower-case letters?
    Simply sticking the later query in the first query does not work.Right; the table name must be given when you compile the query. It's not an expression that you can generate in the query itself.
    Any pointers will be appreciated.In SQL*Plus, you can do something like the query bleow.
    Say you want to count the rows in scott.emp, but you're not certain that the name is emp; it could be emp_2011 or emp_august, or anything else that starts with e. (And the name could change every day, so you can't just look it up now and hard-code it in a query that you want to run in the future.)
    Typically, how dynamic SQL works is that some code (such as a preliminary query) gets some of the information you need to write the query first, and you use that information in a SQL statement that is compiled and run after that. For example:
    -- Preliminary Query:
    COLUMN     my_table_name_col     NEW_VALUE my_table_name
    SELECT     table_name     AS my_table_name_col
    FROM     all_tables
    WHERE     owner          = 'SCOTT'
    AND     table_name     LIKE 'E%';
    -- Main Query:
    SELECT     COUNT (*)     AS cnt
    FROM     scott.&my_table_name
    ;This assumes that the preliminary query will find exactly one row; that is, it assumes that SCOTT has exactly one table whose name starts with E. Could you have 0 tables in the schema, or more than 1? If so, what results would you want? Give a concrete example, preferably suing commonly available tables (like those in the SCOTT schema) so that the poepl who want to help you can re-create the problem and test their ideas.
    Edited by: Frank Kulash on Aug 11, 2011 2:30 PM

  • Can I query with a select statement in the from statement

    I'm working with an application that creates a MASTERTABLE that keeps track of DATATABLEs as it creates them. These data tables are only allowed to be so big, so the data tables are time stamped. What I need to do is to be able to query the MASTERTABLE to find out what the latest datatable is and then query the specific datatable.
    I've tried
    select count(*) from (select max(timestamp) from mastertable)
    and it always comes back with a count of 1.
    Is this possible, or is there a better way?

    Well, I'm trying to understand... and if I understand, then you need something dynamic. I did create the following example, of course not exactly as yours (I don't have your data). Each employee has a table with his name, containing the sal history, and I want to query that table starting from actual sal :
    SCOTT@db102 SQL> select ename from emp where sal= 3000;
    ENAME
    SCOTT
    FORD
    SCOTT@db102 SQL> select * from scott;
    SAL_DATE         SAL
    01-JAN-85       2500
    01-JAN-95       2750
    01-JAN-05       3000
    SCOTT@db102 SQL> set serveroutput on
    SCOTT@db102 SQL> declare
      2     v_rc    sys_refcursor;
      3     tname   varchar2(30);
      4     v_date  date;
      5     v_sal   number;
      6  begin
      7     select max(ename) into tname
      8     from emp
      9     where sal = 3000;
    10     open v_rc for 'select * from '||tname;
    11     loop
    12             fetch v_rc into v_date,v_sal;
    13             exit when v_rc%notfound;
    14             dbms_output.put_line(v_date||' '||v_sal);
    15     end loop;
    16* end;
    SCOTT@db102 SQL> /
    01-JAN-85 2500
    01-JAN-95 2750
    01-JAN-05 3000
    PL/SQL procedure successfully completed.
    SCOTT@db102 SQL>                                                                          

  • A Single query with out the sub-queries

    I am using My-SQL as my back-end and it doesnot support the
    Sub-Queries. i have my table given below
    UserID..UserName..ParentUserID
    1........Admin...........0
    2........Sales...........1
    3........Sourcing........1
    4........SalesHead.......2
    5........SourcingHead....3
    6........SalesExec.......4
    7........SourExec........5
    The table contains heirarchy of users. The top most users
    has the ParentUserID as 0. and the remaining has their own ParentUserID
    I want to get the complete heirarchy of a given user in single ResultSet.
    It should be done without using sub-queries. but all joins can be used.
    e.g.
    if i say userid is 2 i should get following output:
    Sales - > SalesHead -> SalesExec->......
    Can any body please help me out!
    Sridhar.

    Hi Sridhar,
    You can use recursive method. Make a method as follows :
    public String getChildren(int UserID)
         String temp = "";
         Connection con = DriverManager.getConnection("","","");
         Statement st = con.createStatement();
         ResultSet rs = statement.executeQuery("select UserID from MyUsers where ParentUserID = " + UserID);
         while(rs.next())
              temp += " [ ";
              if(temp.equals(""))
                   temp += getChildren(rs(0));
              else
                   temp += " -> " + getChildren(rs(0));
              temp += " ] ";
         return temp;
    then call his method by providing any UserID to it and it will return you a string containing complete hierarchy in the following format :
    AAA -> BBB -> CCC -> DDD
    I hope it will help you.
    regards,
    Humayun

  • Writing alias query with casting

    Dear Experts,
    i want to excute a query which have a condition that needs some casting. the table is MSEG the users are entering the reffrencing article document in the item text field. now all i need is to excute a query which have the mseg aliased and the joining condition should be mblnr with sgtxt
    i imagine it should be something like this
    select * from recmseg,supmseg where supmseg.mblnr=cast(recmseg.sgtxt as blnr)
    recmseg is alias mseg for the recieving site
    supmseg is alias Mseg for suplying site
    so please can you tell me where i can write it and how to excute it and correct the syntax also

    i found it
    REPORT  ZMM_TRANSFER.
    DATA :
           fs_itab TYPE mseg,rs_itab LIKE TABLE OF mseg.
       select MSEG2~mblnr MSEG1~sgtxt
         INTO CORRESPONDING FIELDS
                                   OF TABLE rs_itab
         from MSEG as MSeg1
        inner JOIN
          MSEG as mseg2
                      on
           mseg2~MBLNR = MSEG1~sgtxt.
                                                                                    LOOP AT rs_itab into fs_itab.
      WRITE : / fs_itab-sgtxt,fs_itab-mblnr.
    ENDLOOP.

  • Select query with optional where condition

    Hi,
    Can Anybody help me out in the following problem?
    I have the following query in a procedure.
    SELECT replace(shipper_name,'\',' ') as shipper,
    sum(teus / cntSailings) as teus
    FROM VW_CONTRIBUTION,
    VW_TOTAL_SAILINGS
    WHERE VW_CONTRIBUTION.dir = VW_TOTAL_SAILINGS.DIR
    AND VW_CONTRIBUTION.line = VW_TOTAL_SAILINGS.LINE
    AND VW_CONTRIBUTION.accounting_month = VW_TOTAL_SAILINGS.ACCOUNTING_MONTH
    AND VW_CONTRIBUTION.accounting_year = VW_TOTAL_SAILINGS.ACCOUNTING_YEAR
    AND VW_CONTRIBUTION.Principal = arg_principal
    AND VW_CONTRIBUTION.Dir = arg_direction
    AND VW_CONTRIBUTION.line in ( arg_service )
    AND VW_CONTRIBUTION.POL_country = arg_pol
    AND VW_CONTRIBUTION.POd_country = arg_pod
    AND VW_CONTRIBUTION.salesOffice = arg_SalesOffice
    AND VW_CONTRIBUTION.salesregion = arg_SalesRegion
    AND VW_CONTRIBUTION.cargo_type = arg_txtCargoType
    AND VW_CONTRIBUTION.eqgroup = arg_ContType
    AND VW_CONTRIBUTION.eq_size = arg_txtSize
    AND VW_CONTRIBUTION.acct_date between arg_from_date and arg_end_date
    GROUP BY shipper_name
    ORDER BY teus desc;
    Here some of the arguments are optional(Eg : VW_CONTRIBUTION.salesOffice, AND VW_CONTRIBUTION.eqgroup etc. ) and the values can be null. When they are null, I want them to be excluded from the where condition. Can anybody suggest me a solution for this?
    Thanks,
    Shalet.

    I guess i misunderstood your original question.
    The clause
    AND (VW_CONTRIBUTION.salesOffice = arg_SalesOffice OR VW_CONTRIBUTION.salesOffice IS NOT NULL)
    will cause the where clause to evaluate to FALSE anytime salesOffice IS NULL so the record will be excluded.
    I thought you were asking how to not compare the value if the field contained a NULL.
    Glad you found what you wanted.

  • Query with two where conditions

    HI
    SELECT ENAME FROM EMP WHERE
    SAL > 1000 AND JOB='CLERK';
    How to implement in CMP(Entity bean)
    thank u

    at this point mapping to do this king of query would be on the container specific file. I will tellyou how this is done on a Orion App server. I bet that others are close to the same.
    first you make a finder method in your bean for the enploy name:
    Collection findBigClerk();
    Orion generates a file from the ejb-jar.xml file called orion-ejb-jar.xml. this is where the O/R mapping is changed for the beans.
    each method in a bean has short definition
    <finder-method query="EMP.SAL>1000 and EMP.JOB='CLERK'">
    Assuming that the CMP is mapped to the EMP table when you call findbigClerk it will add the above query to as a WHERE clause.
    Then get the name from the interface.
    Again, this is how I would do this on an Orion App server. Others will be simular until O/R mapping is moved from server-specific to the ejb-jar.xml file
    hope this helps a little

  • Query with multiple where

    Hello,
    I am trying to get query using LINQ to DocumentDB and have some issues.
    This code works fine (example from https://code.msdn.microsoft.com/Azure-DocumentDB-NET-Code-6b3da8af/sourcecode?fileId=132409&pathId=296733303
    var ee = client.CreateDocumentQuery<dynamic>(
    colSelfLink,
    "SELECT f.id, c.FirstName AS child, p.GivenName AS pet " +
    "FROM Families f " +
    "JOIN c IN f.Children " +
    "JOIN p IN c.Pets " +
    "WHERE p.GivenName = 'Fluffy'");
    And converted version also OK
    var ff = client.CreateDocumentQuery<Family>(colSelfLink)
    .SelectMany(family => family.Children
    .SelectMany(children => children.Pets
    .Where(pets => pets.GivenName == "Fluffy")
    .Select(pets => new
    family = family.Id,
    child = children.FirstName,
    pet = pets.GivenName
    But what if I want to add some condition on the "Family"
    var ee = client.CreateDocumentQuery<dynamic>(
    colSelfLink,
    "SELECT f.id, c.FirstName AS child, p.GivenName AS pet " +
    "FROM Families f " +
    "JOIN c IN f.Children " +
    "JOIN p IN c.Pets " +
    "WHERE f.LastName = "123" AND p.GivenName = 'Fluffy'");
    How to write it in LINQ?

    try this -
    var ff = client.CreateDocumentQuery<Family>(colSelfLink)
    .SelectMany(family => family.Children
    .SelectMany(children => children.Pets
    .Where(pets => pets.GivenName
    == "Fluffy" && family.LastName == "Andersen")
    .Select(pets =>
    new
                                family
    = family.Id,
                                child
    = children.FirstName,
                                pet
    = pets.GivenName

  • Use single message with multiple spry "states"

    forgotten past decided to use spry widgets to do the validation. One of the things that can get old pretty quick is to have to create a different message for each thing that can go wrong, even if you need to display the same message. For example, if a user needs to enter 9 digits, the message for entering too few, too many, and letters can pretty much be handled by "The value should be exactly 9 digits."
    Is there a way to use just one div/span and have it show for all of these conditions? I need to be able to code this manually, because for whatever reason the widgets don't show up properly in the DW UI (either because it's an old version or because the widgets have been edited by hand at some point in a way that's incompatible with the DW UI). It also needs to be compatible with older browsers (i.e. I could probably do this by assigning multiple classes to the element(s), but I am not sure what browsers would support this). Many of our users are in libraries, so we have to anticipate that the browser may not be up-to-date.

    Don't use Spry.  Adobe abandoned the framework in 2012.  It is no longer supported.
    Best advice, use HTML5 forms alone or with jQuery validation.  In the following example, the number field requires 9 characters.  This works in modern browsers.
    <form id="MyForm">
    <label for="number">Number:</label>
    <input name="number" type="number"  id="number" placeholder="123456789" maxlength="9" minlength="9" required>
    <input id="submit" name="submit" type="submit" value="SEND">
    </form>
    For older browsers that don't support HTML5 forms, you can add jQuery validation to your forms by adding this to your document's <head> tag.
    <!--LATEST JQUERY CORE LIBRARY-->
    <script src="http://code.jquery.com/jquery-latest.min.js">
    </script>
    <!--JQUERY VALIDATE PLUGIN-->
    <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js">
    </script>
    <!--INVOKE FORM VALIDATION-->
    <script>
    $(document).ready(function() {
        $("#MyForm").validate();
    </script>
    Nancy O.

  • Issue in select query with where clause

    Hi guys,
    I'm facing an issue while using select query with the where clause. When I'm selecting all the data from the table it returns the correct result. But when I'm using the where clause to get the specific rows from the table it returns no rows. But the data I'm trying to fetch using the where condition exists in the table.
    Here is my query which causing the issue,
    select * from mytable where myfield = 'myvalue'
    But if I use the following query it returns the result correctly.
    select * from mytable
    Also the myfield value 'myvalue' exists in the table.
    I have tried by running this query in both SQL Developer and SQL Plus. I have tried this query in mssql as well. It works perfectly and returns correct result sets for both the queries I have mentioned above. I'm unable to predict the issue as I'm new to ORACLE. Please help.
    Thanks,
    Ram.

    Hi Ram,
    I experienced an issue similar to this with a varchar2 field. Some of our records had a hidden newline character at the end of them, which was making queries like the one below fail:
    select * from employees
    where email = '[email protected]'The best way I found to detect this was to use
    select 'XX'||email||'XX' from employeesTo make sure that there were no newlines. But that is just a guess. If you could provide some example table data and the outputs of your selects, it would be helpful.
    Jeff

Maybe you are looking for