Select Query Based on date condition

Hi ,
Is it Possible.
i want to run select query based on date condition.
Eg...
if the date between 01-jan-01 and 01-jan-05 then
select * from table1;
if the date between 02-jan-05 and 01-jan-08 then
select * from table2;
Becaz i have data in 2 diffrent tables , based on the date condition i wnt to run the select statement to diffrent tables.
i dont want plsql here Just SQL needed.
thanks,
-R
Edited by: infant_raj on May 5, 2009 11:48 PM

Helo Kanish,
this is not the one i was asking..
wht i mean was .
i use bind variable to get date while running the select statement , once i get the date then i want to choose any one of the table to run select query.
EG..
select col1,col2 from table1 where date between only if 01-jan-01 and 01-jan-05;
select col1,col2 from table2 where date between only if 02-jan-05 and 01-jan-08;
Run any one of the two . not all
thanks,
_raj                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • SELECT QUERY  BASED ON SECONDARY INDEX

    Hi all,
    CAN ANYONE TELL ME HOW TO WRITE SELECT QUERY BASED ON SECONDARY INDEX.
    IN WHAT WAY DOES IT IMPROVE PERFORMANCE.
    i KNOW WHEN CREATING SECONDARY INDEX I NEED TO GIVE AN INDEX NO -iT SHOULD BE ANY NUMBER RIGHT?
    I HAVE TO LIST ALL PRIMARY KEYS FIRST AND THEN THE FIELD FOR WHICH I AM CREATING SECONDARY INDEX RIGHT?
    LETS SAY I HAVE 2 PRIMARY KEYS AND I WANT TO CREATE SEONDARY INDEX FOR 2 FIELDS THEN
    I NEED TO CREATE A SEPERTE SECONDARY INDEX FOR EACH ONE OF THOSE FIELDS OR ONE SHOULD BE ENOUGH
    pLS LET ME KNOW IF IAM WRONG

    HI,
    If you cannot use the primary index to determine the result set because, for example, none of the primary index fields occur in the WHERE or HAVINGclauses, the system searches through the entire table (full table scan). For this case, you can create secondary indexes, which can restrict the number of table entries searched to form the result set.
    You create secondary indexes using the ABAP Dictionary. There you can create its columns and define it as UNIQUE. However, you should not create secondary indexes to cover all possible combinations of fields.
    Only create one if you select data by fields that are not contained in another index, and the performance is very poor. Furthermore, you should only create secondary indexes for database tables from which you mainly read, since indexes have to be updated each time the database table is changed. <b>As a rule, secondary indexes should not contain more than four fields</b>, <b>and you should not have more than five indexes for a single database table</b>.
    <b>What to Keep in Mind for Secondary Indexes:</b>
    http://help.sap.com/saphelp_nw04s/helpdata/en/cf/21eb2d446011d189700000e8322d00/content.htm
    http://www.sap-img.com/abap/quick-note-on-design-of-secondary-database-indexes-and-logical-databases.htm
    Regards
    Sudheer

  • 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

  • Query based on date partition

    Hi,
    I am trying to output only a successful job during the past 24 hrs of each day. If there is job that has an outcome of a success and a failure within the last
    24 hrs for each day, I want to only output the successful one. If there are no success for the same job, I will output the last attempted failed job.
    Here are my columns:
    current output:
    JOB_ID     JOBDATE               GROUP     PATH          OUTCOME          FAILED     LEVEL     ASSET
    3400908     7/27/2012 10:01:18 AM     polA     target1          Success          0     incr     clone1
    3400907     7/27/2012 10:01:09 AM     polA     target1          Failed          0     incr     clone1
    3389180     7/23/2012 10:01:14 AM     polA     target1          Failed          1     incr     clone1
    3374713     7/23/2012 10:01:03 AM     polA     target1          Success          0     incr     clone1
    3374712     7/22/2012 11:24:32 AM     polA     target1          Success          0     Full     clone1
    3367074     7/22/2012 11:24:00 AM     polA     target1          Failed          1     Full     clone1
    3167074     7/21/2012 10:01:13 AM     polA     target1          Success          0     incr     clone1
    336074     7/21/2012 10:01:08 AM     polA     target1          Success          0     incr     clone1
    desired output:
    JOB_ID     JOBDATE               GROUP     PATH          OUTCOME          FAILED     LEVEL     ASSET
    3400908     7/27/2012 10:01:18 AM     polA     target1          Success          0     incr     clone1
    3374713     7/23/2012 10:01:03 AM     polA     target1          Success          0     incr     clone1
    3374712     7/22/2012 11:24:32 AM     polA     target1          Success          0     Full     clone1
    3167074     7/21/2012 10:01:13 AM     polA     target1          Success          0     incr     clone1
    Here is a code I am trying to use without success:
    select *
    from
       (selectjob_id, jobdate, group, path, outcome, Failed, level, asset,
              ROW_NUMBER() OVER(PARTITION BY group, path, asset ORDER BY jobdate desc) as rn
                   from job_table where jobdate between trunc(jobdate) and trunc(jobdate) -1 )
       where rn = 1
       order by jobdate desc;Thanks,
    -Abe

    Hi, Abe,
    You're on the right track, using ROW_NUMBER to assign numbers, and picking only #1 in the main query. The main thing you're missing is the PARTITION BY clause.
    You want to assign a #1 for each distinct combination of group_id, path, asset and calendar day , right?
    Then you need to PARTITION BY group_id, path, asset and calendar day . I think you realized that when you named this thread "Query Based *on date partition* ".
    The next thing is the analytic ORDER BY clause. To see which row in each partition gets assigned #1, you need to order the rows by outcome ('Success' first, then 'Failed'), and after that, by jobdate (latest jobdate first, which is DESCending order).
    If so, this is what you want:
    WITH     got_r_num     AS
         SELECT  j.*     -- or list columns wanted
         ,     ROW_NUMBER () OVER ( PARTITION BY  group_id     -- GROUP is not a good column name
                                   ,                    path
                             ,             asset
                             ,             TRUNC (jobdate)
                                   ORDER BY          CASE  outcome
                                                 WHEN  'Succcess'
                                         THEN  1
                                         ELSE  2
                                             END 
                             ,             jobdate     DESC
                           )      AS r_num
         FROM    job_table  j
         WHERE     outcome     IN ('Success', 'Failed')
    --     AND     ...     -- Any other filtering, if needed
    SELECT     *       -- or list all columns except r_num
    FROM     got_r_num
    WHERE     r_num     = 1
    ;If you'd care to post CREATE TABLE and INSERT statements for the sample data, then I could test it.
    It looks like you posted multiple copies of this thread.  I'll bet that's not your fault; this site can cause that.  Even though it's not your fault, please mark all the duplicate versions of this thread as "Answered" right away, and continue in this thread if necessary.
    Edited by: Frank Kulash on Jul 28, 2012 11:47 PM
    This site is flakier than I thought! I did see at least 3 copies of this same thread earlier, but I don't see them now.

  • Select query based LOV for tabular form attributes

    Hi HTMLDB Team,
    Congrats u all for the new release of HTMLDB in htmldb.oracle.com.
    I badly need a solution of the below problem.
    Say , i have table called user_col_comments now i want to display the table_name ,column_name and comments in a tabular form.I displayed only one row for the tabular form.Now i create a select query based LOV for attribute table_name where i got all table_name in drop down list.
    Point is that after selecting any data from drop down table list i want to get the corresponding fields to be populated in column_name attributes.How can i wrote the select query based LOV for the attibute column_name.
    I wrote it as 'select column_name d,column_name r from user_col_comments where table_name=:TABLE_NAME Its not working?
    Similarly i want same thing to display for comments after matching both table_name and column_name.
    Any solution to get rid of those problem will be highly appreciable...
    If u need my htmldb.oracle.com userid and password to solve the problem i will sure let u email it.
    Cheers,
    Eman

    hi rchalton,
    can u plz little bit more clearer .I know hopefully u can imagine the problem and may u guide me thru proper way.....One think i understand that there must be multiple process and submit but "only when..." that u have said i cant understand that part........
    U are welcome to give me proper solution.....
    Thanks for the reply ....atleast one can pay hid to me.....
    Cheers,
    Eman

  • Select query based on userinput

    Hi Folks...
    I posted this in another forum, but no reply,so I am posting it here too. I am trying to make a select query based on a user input. Earlier I was having probelms making a select query and printing out the result in the stack trace,with the advice given, I managed to solve that. I am now modifying that code to make a query based on user input, however it's not working, following is the code:
    String userId = request.getRemoteUser();  String sql = "SELECT hoursused FROM sysuser WHERE iduser = ?";    try      {        Connection connection = dataSource.getConnection();        PreparedStatement preparedStatement = connection.prepareStatement(sql);        preparedStatement.setString(1, userId);                ResultSet srs = preparedStatement.executeQuery(sql);                            while(srs.next()) {                          String hoursused = srs.getString("hoursused");                          System.out.println("The hours used are " + hoursused);    }                  }    catch (SQLException e)      {    e.printStackTrace();    }        } 
    stack trace seems to suggest I may have a probelm with this statement:
    "SELECT hoursused FROM sysuser WHERE iduser = ?"; 
    I am not sure how to rectify this, I hope someone can advise, thanks.

    Hi jschell..
    Thanks for responding, I appreciate it. The problem has been solved. No 'sysuser' is not a reserved word in Mysql. Based on the advice given in another forum and also from this site, I managed to solve the problem. I only made one change. This:
    ResultSet srs = preparedStatement.executeQuery(sql);     was changed to this:
    ResultSet srs = preparedStatement.executeQuery();  Thanks.

  • Select Query Between two dates...

    Hi Guru's,
    I need a Select Query between two dates, also if the record not found for any in between date then it should return NULL or 0 ...
    for Example
    1. I am having two records in DB for date 2-10-2008 & 4-10-2008
    2. Now suppose I have given Query for date between 1-10-2008 to 5-10-2008
    Then it should return me 5 records with valid values for 2 & 4 and NULL for other 1,3,5
    Thanks.

    Try like this:
    with
      t as
          select date '2008-10-02' as dt, 'Record #1 (in DB)' as str from dual union all
          select date '2008-10-04' as dt, 'Record #2 (in DB)' as str from dual
    select v.dt, t.str
      from (
             select date '2008-10-01' + level - 1 as dt
               from dual
             connect by level <= (date '2008-10-05' - date '2008-10-01') + 1
           ) v
      left join t
        on v.dt = t.dt
    order by 1

  • Select query based on joining of tables from different database is taking too long

    Hi Team,
    Select query on table with millions of records is taking very long time. It took 50mins, the below query is joining on multiple table from two databases DB1.dbo.Table1 contains 100 million records and also Table3 and Table4 (of different database) might
    contain close to 1million records.
    Select T1.*
    From DB1.dbo.Table1 T1
    Join DB1.dbo.Table2 T2 on RTRIM(T1.Col3) = RTRIM(T2.Col3)
    Join Table4 CA on RTRIM(T1.Col1) + T2.Col2 = CA.Col1
    Join Table3 U on CA.Col2 = U.Col2 AND RTRIM(T2.Col2) = U.Col3
    Where U.Col4 NOT IN ('A1', 'A2', 'A3', 'A4', 'A5', 'A6','A7','A8','A9')
    And (T1.flg IS NULL OR T1.flg = 'N')
    And LTRIM(RTRIM(T2.Col2)) NOT IN ('B1','B2')
    How can i improve the performance of this query. Actual thing is update the data in Db1.dbo.table1 based on the conditions but if the select is taking close to 1hr then update will take hours together. Indexes already implemented on all the tables.
    Thanks,
    Eshwar.
    Please don't forget to Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful. It will helpful to other users.

    Thanks.
    Join Table4 CA on RTRIM(T1.Col1) + T2.Col2 = CA.Col1
    This join is not working with spaces if Rtrim is not used.
    Thanks! Eshwar.
    Please don't forget to Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful. It will helpful to other users.

  • Selecting material based on date

    Hello Experts,
    I have requirement where i want to give material and date.
    i have to select materia, condition record number based on date.
    In database table field is stored like material , validity from date and validity to date.
    Same material number is there but validity date and condtion record number is different.
    Matno        from date                 to date                      Condition record no
    1234       01.01.2009                31.12.2009                       23456
    1234       01.01.2008                31.12.2008                       12367
    if user enter date 12.09.2009 it should fetch me first record. ( because date is between 01.01.2009 to 31.12.2009)
    if user enter date 20.08.2008 it should fetch me first record. ( because date is between 01.01.2008 to 31.12.2008)
    field for input date is fkdate.
    So how i have to query in select statement to get this requirement.
    Thanks in advance.
    Best regards,
    Sai

    select * "or the fields you need
           from abcd
            into table itab
            where matnr in s_matnr "if you have it in sel screen or remove it..
                 and dat_fr GE p_fkdat
                 and dat_to LE p_fkdat.
    but if the dates are not keys...
    better not use them in select...
    delete the unnecessary items after the select using DELETE ITAB where...

  • Select Product based on date

    Hai,
    Product Date
    pd0 2012-08-11 18:45:55.780
    Pd1 2012-08-11 18:55:17.020
    pd2 2012-08-11 19:06:58.623
    pd3 2012-08-18 12:00:01.193
    pd4 2012-08-25 12:13:04.077
    pd5 2012-08-25 17:28:30.347
    pd6 2012-08-25 18:23:16.473
    pd7 2012-09-18 18:29:58.360
    I want select the product based on from date and to date.
    For Example
    I want the select the product date in between 2012-08-11 to 2012-08-18
    Note:dont check the time.
    I want the query for select product based on only date not depend upon time

    >
    Product Date
    pd0 2012-08-11 18:45:55.780
    Pd1 2012-08-11 18:55:17.020
    pd2 2012-08-11 19:06:58.623
    pd3 2012-08-18 12:00:01.193
    pd4 2012-08-25 12:13:04.077
    pd5 2012-08-25 17:28:30.347
    pd6 2012-08-25 18:23:16.473
    pd7 2012-09-18 18:29:58.360
    I want select the product based on from date and to date.
    For Example
    I want the select the product date in between 2012-08-11 to 2012-08-18
    >
    Hopefully what you are calling 'Date', which is actually a timestamp value, is really being stored in a column of datatype TIMESTAMP and not being stored in a VARCHAR2.
    NEVER store date or datetime values in a character datatype. And the word BETWEEN, when used as an operator means that BOTH endpoints will be included.
    1. Data is stored in a TIMESTAMP column the way it should be stored
    WITH Q AS (SELECT 'pd0' PRODUCT, TO_TIMESTAMP('2012-08-11 18:45:55.780', 'YYYY-MM-DD HH24:MI:SS.FF3') myBadDateFormat from dual
    UNION ALL SELECT 'Pd1',TO_TIMESTAMP('2012-08-11 18:55:17.020', 'YYYY-MM-DD HH24:MI:SS.FF3') from dual
    UNION ALL SELECT 'pd2',TO_TIMESTAMP('2012-08-11 19:06:58.623', 'YYYY-MM-DD HH24:MI:SS.FF3') from dual
    UNION ALL SELECT 'pd3',TO_TIMESTAMP('2012-08-18 12:00:01.193', 'YYYY-MM-DD HH24:MI:SS.FF3') from dual
    UNION ALL SELECT 'pd4',TO_TIMESTAMP('2012-08-25 12:13:04.077', 'YYYY-MM-DD HH24:MI:SS.FF3') from dual
    UNION ALL SELECT 'pd5',TO_TIMESTAMP('2012-08-25 17:28:30.347', 'YYYY-MM-DD HH24:MI:SS.FF3') from dual
    UNION ALL SELECT 'pd6',TO_TIMESTAMP('2012-08-25 18:23:16.473', 'YYYY-MM-DD HH24:MI:SS.FF3') from dual
    UNION ALL SELECT 'pd7',TO_TIMESTAMP('2012-09-18 18:29:58.360', 'YYYY-MM-DD HH24:MI:SS.FF3') from dual)
    SELECT PRODUCT FROM Q
      WHERE myBadDateFormat BETWEEN TO_TIMESTAMP('2012-08-11', 'YYYY-MM-DD')
                                AND TO_TIMESTAMP('2012-08-18', 'YYYY-MM-DD')
    PRODUCT
    pd0
    Pd1
    pd2If you don't want the second endpoint included you need to use > and <= operators instead of BETWEEN.
    2. Data is stored in a VARCHAR2 column the way it should NEVER be stored
    WITH Q AS (SELECT 'pd0' PRODUCT, '2012-08-11 18:45:55.780' myBadDateFormat from dual
    UNION ALL SELECT 'Pd1','2012-08-11 18:55:17.020' from dual
    UNION ALL SELECT 'pd2','2012-08-11 19:06:58.623' from dual
    UNION ALL SELECT 'pd3','2012-08-18 12:00:01.193' from dual
    UNION ALL SELECT 'pd4','2012-08-25 12:13:04.077' from dual
    UNION ALL SELECT 'pd5','2012-08-25 17:28:30.347' from dual
    UNION ALL SELECT 'pd6','2012-08-25 18:23:16.473' from dual
    UNION ALL SELECT 'pd7','2012-09-18 18:29:58.360' from dual)
    SELECT PRODUCT FROM Q
      WHERE myBadDateFormat BETWEEN '2012-08-11' AND '2012-08-18'
    PRODUCT
    pd0
    Pd1
    pd2Neither of the solutions posted by others so far will work unless your data is stored in a TIMESTAMP column and even then Oracle will rewrite the filter to use TIMESTAMP values
    SQL> select product from test_timestamp
      2    WHERE myBadDateFormat < DATE '2012-08-18'
      3      AND myBadDateFormat >= DATE '2012-08-11'
      4  /
    Execution Plan
    Plan hash value: 3988574921
    | Id  | Operation         | Name           | Rows  | Bytes | Cost (%CPU)| Time   |
    |   0 | SELECT STATEMENT  |                |     3 |    54 |     3   (0)| 00:00:01 |
    |*  1 |  TABLE ACCESS FULL| TEST_TIMESTAMP |     3 |    54 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter("MYBADDATEFORMAT"<TIMESTAMP'2012-08-18 00:00:00' AND
                  "MYBADDATEFORMAT">=TIMESTAMP'2012-08-11 00:00:00')
    Note
       - dynamic sampling used for this statement

  • Query based on date

    Have you guys ever tried to write a query based on CMP?
    The EJB QL is:
    select object(a) from ActionItems as a where a.duedate = ?1
    When I deployed it to OC4J, I got the following error:
    Error compiling D:\oc4j903\j2ee\home\applications\biogen/biogen.jar: Error trans
    lating EJBQL: Invalid type for expression (a.dueDate = ?1)
    EJB QL statement : 'select object(a) from ActionItems as a where a.dueDate = ?1'
    EJB QL method : public abstract java.util.Collection ActionItemsLocalHome.findByDueDate(java.sql.Date) throws javax.ejb.FinderException
    Auto-deploying file:/D:/oc4j903/j2ee/home/applications/biogen/biogen/ (Assembly
    had been updated)...
    So, any query that is based on date will not work for OC4J, is this a bug or what?
    Thanks for the reply.
    Jingzhi

    I would post this question (and your date range question) to the J2EE group. More J2EE/EJB specific questions are answered there.
    To my understanding the standard ejb2.0 specification is weak in date comparisons for queries. I believe you need to add your date queries to your application server specific orion-ejb-jar.xml file. I'm not sure of how, I would post that question to the J2EE forum, or look it up in the 9ias documentation.
    -Mark

  • Issue with select query to fetch data using Join from two tabels

    Hello All-
    I want to fetch the ShowName as "SUN NIGHTLY NEWS" and EpisodeName as "091706"
    based on the condition a.TitleNo=b.TitleNo and a.seriesNo=b.TitleNo.
    If i use the only first condition-a.TitleNo=b.TitleNo than output is displayed as-
    SchedItemNo |      Showname|      EpisodeName
    2702154     |     091706     |     091706
    If i use the second Condition-a.seriesNo=b.TitleNo than Output is displayed as-
    SchedItemNo|     Showname      |     EpisodeName
    2702154     |     SUN NIGHTLY NEWS |     SUN NIGHTLY NEWS
    Than i tried following Query to use the Union based on two conditions:-
    Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
    from ScheduleItem a,Titles b where a.TitleNo=b.TitleNo and
    a.ScheditemNo in ('2702154')
    Union All
    Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
    from ScheduleItem a,Titles b where b.TitleNo=a.SeriesNo and
    a.ScheditemNo in ('2702154')
    than it display the following result-
    SchedItemNo|     Showname |     EpisodeName
    2702154     |     091706          |     091706
    2702154     |     SUN NIGHTLY NEWS |     SUN NIGHTLY NEWS
    Here also values are not what i want :(
    I want the result to be displayed as using SQL:-
    SchedItemNo |     Showname      |     EpisodeName
    2702154     |     SUN NIGHTLY NEWS |     091706
    Please help me out!
    Thanks in Advance for putting your efforts.Looking forward for your replies.

    SQL> create table scheduleitem
      2  as
      3  select 2702154 scheditemno, 1 titleno, 11 seriesno from dual
      4  /
    Tabel is aangemaakt.
    SQL> create table titles
      2  as
      3  select 1 titleno, '071706' titlename from dual union all
      4  select 11, 'SUN NIGHTLY NEWS' from dual
      5  /
    Tabel is aangemaakt.
    SQL> Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
      2  from ScheduleItem a,Titles b where a.TitleNo=b.TitleNo and
      3  a.ScheditemNo in ('2702154')
      4  /
                               SCHEDITEMNO TITLENAME        EPISODENAME
                                   2702154 071706           071706
    1 rij is geselecteerd.
    SQL> Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
      2  from ScheduleItem a,Titles b where b.TitleNo=a.SeriesNo and
      3  a.ScheditemNo in ('2702154')
      4  /
                               SCHEDITEMNO TITLENAME        EPISODENAME
                                   2702154 SUN NIGHTLY NEWS SUN NIGHTLY NEWS
    1 rij is geselecteerd.
    SQL> Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
      2  from ScheduleItem a,Titles b where a.TitleNo=b.TitleNo and
      3  a.ScheditemNo in ('2702154')
      4  Union All
      5  Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
      6  from ScheduleItem a,Titles b where b.TitleNo=a.SeriesNo and
      7  a.ScheditemNo in ('2702154')
      8  /
                               SCHEDITEMNO TITLENAME        EPISODENAME
                                   2702154 071706           071706
                                   2702154 SUN NIGHTLY NEWS SUN NIGHTLY NEWS
    2 rijen zijn geselecteerd.
    SQL> select a.SchedItemNo "SchedItemNo"
      2       , show.TitleName "Showname"
      3       , episode.TitleName "EpisodeName"
      4    from ScheduleItem a
      5       , Titles episode
      6       , Titles show
      7   where a.TitleNo = episode.TitleNo
      8     and a.SeriesNo = show.TitleNo
      9  /
                               SchedItemNo Showname         EpisodeName
                                   2702154 SUN NIGHTLY NEWS 071706
    1 rij is geselecteerd.Regards,
    Rob.

  • Select query for rows where condition 1

    Say I have a table, tb1, that has the following entries:
    FName LName
    Code
    John Doe
    xxx
    Jane Doe
    xxx
    Steve Harper
    x
    Barrak Obama
    x
    George Bush
    xxxx
    Bill Clinton
    xx
    I'd like to write a select query that only lists the rows where the count for Code is > 1, i.e not display the last two rows from the above entry. How would I go about writing that select query.
    Thanks.

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. 
    >> Say I have a table, tb1, that has the following entries: <<
    Are you this rude or really ignorant and too lazy to read the Netiquette at the start to this forum? Why do you think you do not need a key? No DDL? No constraints? And , why, why do you think that “tb1” is a precise, ISO-11179 conforming table name? 
    Let's make this a table of rude posters rated on a 4-star scale. 
    CREATE TABLE Rude_Posters
    (first_name VARCHAR(15) NOT NULL, 
     last_name VARCHAR(15) NOT NULL, 
     PRIMARY KEY (first_name, last_name), 
     rudeness_code VARCHAR (4) NOT NULL
       CHECK (rudeness_code IN ('x', 'xx', 'xxx', 'xxxx'));
    INSERT INTO Rude_Posters
    VALUES
    ('John', 'Doe', 'xxx'), 
    ('Jane', 'Doe', 'xxx'), 
    ('Steve', 'Harper', 'x'), 
    ('Barrack', 'Obama', 'x'), 
    ('George', 'Bush', 'xxxx'), 
    ('Bill', 'Clinton', 'xx');
    >> I'd like to write a SELECT query that only lists the rows where the count for rudeness_code is > 1, i.e not display the last two rows from the above entry. << 
    The rudeness scale is based on stars, so to ask for an integer value is like saying “on a scale from 1 to 10, what is the color of your favorite letter of the alphabet?”
    Next, the number of stars and your narrative do not match. Did you want to say WHERE rudeness_code IN ('xx' 'xxx', 'xxxx')? 
    Please stop programming SQL until you have gotten more education. At this point, you do not know enough to ask a question. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Select query to read data from a view

    Hi friends,
    We have been using a query to read data from a custom view which used to work perfectly. Now the program sits at that select query forever. We are able to extract same data from se16. Not sure what could be the problem.
    Thanks in advance.

    Dev
    Have a look at the Table Index for the tables involved in the View... I think there is some change in the Indexes.. (Add / Remove / Change)
    Thanks
    Amol Lohade

  • Select query with blank date

    Hi All,
    I have issue with my select query, this query should execute when the date is empty in the table. Fields for the date is (trrecv and trpay)
    code:
    SELECT * FROM zcat3_mov
                       INTO CORRESPONDING FIELDS OF
                       TABLE lt_invmov
                       WHERE bukrs  EQ zcat3_mov-bukrs
                       AND trans EQ zcat3_mov-trans
                       AND status EQ 'CD'
                       AND clear  EQ ' '
                       AND trrecv EQ ' '
                       AND trpay  EQ ' '.
    Thanks,
    FED

    Hi,
    to check for blank date fields in database tables always use :
    date1 = '00000000'
    so your query will be -
    SELECT * FROM zcat3_mov INTO CORRESPONDING FIELDS OF TABLE lt_invmov
                            WHERE bukrs  EQ zcat3_mov-bukrs  AND
                                  trans  EQ zcat3_mov-trans  AND
                                  status EQ 'CD'             AND
                                  clear  EQ ' '              AND
                                  trrecv EQ '00000000'       AND
                                  trpay  EQ '00000000 '.
    regards,
    Shaurabh Pandey

Maybe you are looking for

  • Display page in Interactive Report

    Hello everyone, I was trying to figure out how to display a new page in the main page when a link is clicked (link is in the main page) To explain it better: I have page 900 which is an interactive report when we click on the first link of of the rep

  • MB5S Report

    Dear All, I am using MB5S Report for GR/IR Clearing balance. My client wants cleared Items only. (MIRO completed only.).I am selecting Cleared items too check box only then execute. But i am not getting all cleared items. (MIRO completed only). Pleas

  • Any Other Dinosaurs Out There?  Need PhotoDeluxe Business Edition 1.0 Help (Restore after Crash)

    I'm still using BE 1.0 and very happy with it, but in rare instances it crashes. It leaves behind a file named ~PDTnnnn.tmp in my "...\Local Settings\Temp" folder. Is it possible to restore the session from this file?

  • How to use stack canvas in tab canvas in oracle forms

    hi all, how to use stack canvas in tab canvas in oracle forms. please if any one help out in this.

  • Unable to stop Skype loading at start up

    When I go to tools and click on Options, then try to uncheck the Start Skype when I start Windows I get an error saying something about ports.  Screen shot attached.  Please fix.