Query between docdate and doctime

Hi,
I am having trouble in my query.I want to get the date that has date between 03/09/2015 and 03/10/2015 and time between 6:00AM of 03/09/2015 and 7:00AM of 03/10/2015 but it only show date with time between 6:00AM and 7:00Am of each date.
This is my query
SELECT T0.[DocDate], T0.[DocNum], T1.[Dscription], T1.[Quantity],T0.[DocTime] FROM OIGN T0  INNER JOIN IGN1 T1 ON T0.DocEntry = T1.DocEntry WHERE T0.[DocDate] between [%0] and [%1] and T0.[DocTime] >= [%2] and T0.[DocTime]<=[%3]
Thanks,
Raphael

Hi Raphael Mendoza
Have you check the database does it have data between those time slot...
Also you use between option
SELECT T0.[DocDate],
   T0.[DocNum],
   T1.[Dscription],
   T1.[Quantity],
   T0.[DocTime]
FROM OIGN T0
INNER JOIN IGN1 T1 ON T0.DocEntry = T1.DocEntry
WHERE T0.[DocDate] BETWEEN [%0] AND [%1]
  AND T0.[DocTime] BETWEEN [%2] AND [%3]
Regards
Kennedy

Similar Messages

  • Urgent - I have written select query between loop and endloop, Ple help out

    Can any one help out me on this select query. I have written select query between loop and endloop. When I execute the program it will take too much time in this query. Please help me out. Its very urgent.
    LOOP AT l_i_invoices ASSIGNING <l_invoices>.
          CLEAR alv_wa.
          alv_wa-bukrs = <l_invoices>-bukrs.
          alv_wa-gsber = <l_invoices>-gsber.
          CLEAR l_instid.
          CONCATENATE <l_invoices>-belnr <l_invoices>-gjahr INTO l_instid.
          SELECT top_wi_id FROM sww_wi2obj INTO TABLE l_i_swwwihead
                  WHERE catid   = c_catid_business_object
                    AND instid  = l_instid
                    AND typeid  = c_typeid_invoice
                    AND removed = space
                    AND ( wi_rh_task = c_task_buyer_message
                       OR wi_rh_task = c_task_buyer_message2 ).
          IF sy-subrc = 0.
            <l_invoices>-flag = 'X'.
          ELSE.
            <l_invoices>-flag = ' '.
          ENDIF.
          MODIFY l_i_invoices FROM <l_invoices> TRANSPORTING flag
                                WHERE belnr = <l_invoices>-belnr
                                   AND gjahr = <l_invoices>-gjahr.
          APPEND alv_wa TO i_alv.
        ENDLOOP.
    Thanks in advance.

    Here is a way to solve this problem.
    Choose somewhere before this loop processing to use that select. Therefore, you'll need use FOR ALL ENTRIES <that_loop_table> clause, and in the WHERE condition you need to specify that same fields.
    This way, you will have an internal table with all data you'll need to check.
    Then, inside your loop statement, use the READ TABLE command with the clause WITH KEY field = value, to read that record and use the value found.
    Like this sample:
      SELECT bukrs lifnr umsks umskz augdt augbl zuonr gjahr belnr buzei
             waers xblnr blart gsber ebeln zfbdt zbd1t zlsch
      INTO TABLE tg_bsak
      FROM bsak
      FOR ALL ENTRIES IN tl_bkpf_sel
      WHERE bukrs EQ tl_bkpf_sel-bukrs AND
            lifnr IN s_lifnr AND
            augbl EQ tl_bkpf_sel-belnr.
    LOOP AT tg_bseg INTO wa_bseg.
        READ TABLE tg_bsak INTO wa_bsak WITH KEY bukrs = wa_bseg-bukrs
                                                 gjahr = wa_bseg-gjahr
                                                 belnr = wa_bseg-belnr
                                                 BINARY SEARCH.
    if sy-subrc = 0.
    * do something
    endif.
    ENDLOOP.

  • Joins query between itab and database table..

    Hi all,
    Is it posible to use joins query between internle table and data base table...

    Hi Mehboob,
    No thats impossible to join the internal table and the database table.
    Alternatively what you need to do is you need to execute a Queryin Database Table and use the For All Entries in itab.
    Eg:  Select * from marc into table it_marc
             for all entries in it_matnr
               where matnr = it_matnr-matnr.
    Thanks,
    Chidanand

  • Date range query between day1 and day1-14

    I am using:
    Oracle SQL Developer (3.0.04)
    Build MAin-04.34
    Oracle Database 11g
    Enterprise Edition 11.2.0.1.0 - 64bit Production
    I am having diffitult time getting this filter to work:
    {Code}
    where date_value between :day1 and :day1 - 14
    {Code}
    What am I doing wrong?
    I am looking to input a single day and have it give a range of 14 days back. So if I put "25-JUN-2013" it should include that day and track back 14 days.

    1007410 wrote:
    where date_value between :day1 and :day1 - 14
    Reverse the order.
    You generally specify a range from LOW to HIGH. Or in dates, EARLIER to LATER.
    You've done the reverse.
    Basically instead of saying "Pick a number from 1 to 10", you said "Pick a number from 10 to 1".
    with xx as
       ( select to_date('25-jun-2013', 'dd-mon-yyyy') d from dual union all
         select to_date('20-jun-2013', 'dd-mon-yyyy') d from dual union all
         select to_date('15-jun-2013', 'dd-mon-yyyy') d from dual union all
         select to_date('05-jun-2013', 'dd-mon-yyyy') d from dual
    Select d
      from xx
    where d between sysdate and sysdate-14 ;
    no rows selected.
    with xx as
       ( select to_date('25-jun-2013', 'dd-mon-yyyy') d from dual union all
         select to_date('20-jun-2013', 'dd-mon-yyyy') d from dual union all
         select to_date('15-jun-2013', 'dd-mon-yyyy') d from dual union all
         select to_date('05-jun-2013', 'dd-mon-yyyy') d from dual
    Select d
      from xx
    where d between sysdate-14 and sysdate;
    D       
    25-JUN-13
    20-JUN-13
    15-JUN-13
    3 rows selected.

  • Error while copy query between infocubes

    I was trying to copy a query between infocubes and ended with error message.
    Query copied from Infocube A to Infocube B. Infocube B has an additional dimension with 2 char's when compared to infocube A.
    Using transaction RSZC, I tried to copy the query, but ended up with following error..
    1.Program error in class COPY_QRY_TO_CUBE method : UNCAUGHT_EXCEPTION
    2.An exception with the type CX_SY_OPEN_SQL_DB occurred, but was neither handled locally, nor declared in a RAISING clause
    3.The system tried to insert a data record, even though a data record with the same primary key already exists
    I also tried using function module RSZ_I_COPY_QRY_TO_CUBE, which was of no help. I get the following message with the function module...
    1. Program error in class RS_TESTFRAME_CALL method : UNCAUGHT_EXCEPTION
    2. An exception with the type CX_SY_OPEN_SQL_DB occurred, but was neither handled locally, nor declared in a RAISING clause
    3. The system tried to insert a data record, even though a data record with the same primary key already exists
    I have also tried a solution in BW expert by using debugging mode of the above function module, again this was of no help..
    I am BI 7.0 SP09...
    Any ideas, Please....
    Thanks,
    RR
    Message was edited by:
            Ray R

    Hello,
    Are you trying to copy Business Content delivered Queries?
    I had also got this error when copying over all queries from one cube to another. Reason for this message was plain simple - I did not realise that the sender Cube had Business Content Query which we cannot copy over using RSZC as system tries to create another query with suffix as 0****_1. We cannot create query in SAP user namespace. Error message is different then the reason behind it.
    Thanks
    Ravi

  • Simple Select query with 'where', 'and', 'between' clauses takes time

    Hi,
    I have a select query as below
    SELECT * FROM (SELECT a.*,ROWNUM currentStartRecord From (select ai_inbound.ai_inb_seq tableseq,'AI_INBOUND' tablename,'INBOUND' direction,ai_inbound.appl,ai_inbound.ai_date datetime,ai_inbound.ic_receiver_id pg_id,ai_inbound.ic_sender_id tp_id,ai_inbound.session_no,ai_inbound.ic_ctl_no,ai_inbound.msg_set_id msg_type,ai_inbound.appl_msg_ctl_no reference_no,ai_inbound.fg_version version,ai_inbound.msg_status status,ai_inbound.input_file_name,ai_inbound.output_file_name,ai_inbound.ack_file_name from ai_inbound where ai_inbound.appl = ? and ai_inbound.ai_date between ? and ? )a where ROWNUM <= 49)where currentStartRecord >= 0
    The above query takes longer time through application than expected when the date fields are passed whereas it works fine when no date fields are passed. We are using oracle9.2 version of the database. All the indexed columns and partitioned indexed columns are rebuild.
    Kindly let me know how can i tune up the query to improve the performance.
    Thanks

    Hi,
    I have a select query as below
    SELECT * FROM (SELECT a.*,ROWNUM currentStartRecord From (select ai_inbound.ai_inb_seq tableseq,'AI_INBOUND' tablename,'INBOUND' direction,ai_inbound.appl,ai_inbound.ai_date datetime,ai_inbound.ic_receiver_id pg_id,ai_inbound.ic_sender_id tp_id,ai_inbound.session_no,ai_inbound.ic_ctl_no,ai_inbound.msg_set_id msg_type,ai_inbound.appl_msg_ctl_no reference_no,ai_inbound.fg_version version,ai_inbound.msg_status status,ai_inbound.input_file_name,ai_inbound.output_file_name,ai_inbound.ack_file_name from ai_inbound where ai_inbound.appl = ? and ai_inbound.ai_date between ? and ? )a where ROWNUM <= 49)where currentStartRecord >= 0
    The above query takes longer time through application than expected when the date fields are passed whereas it works fine when no date fields are passed. We are using oracle9.2 version of the database. All the indexed columns and partitioned indexed columns are rebuild.
    Kindly let me know how can i tune up the query to improve the performance.
    Thanks

  • Parallel database connection​s and single query between databases

    Hi, I am looking to execute this SQL query between 2 different databases to update a local database based on data selected from a remote one.
    e.g.:
    - Local database name: db1
    - local database schema: dbo
    - local database table1
    - remote database name: db2
    - remote database schema: dbo
    - Remote database table: table2
    - Query: "SELECT * FROM db2.dbo.table2 WHERE NOT EXISTS(SELECT * FROM db1.dbo.table1)" <- This gets e the record set i would need to insert, and I already have a vi to do that kinda thing.
    How do I go about this?
    Thanks,
    Mohamed

    Mohamed,
    There is a VI in the Database Connectivity Toolkit that allows you to execute SQL queries:  DB Tools Execute Query.
    http://zone.ni.com/reference/en-XX/help/370016E-01​/lvdatabase/db_tools_execute_query/
    Is this what you are looking for?
    Drew T.
    NIC AE Specialist

  • Different Between In and Join Function of Query

    Hi Team,
    I have confuse for the below query getting different count.
    Version DB :-
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE     11.2.0.1.0     Production
    TNS for Linux: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    Query:-1
    Getting Count :-3917
    SELECT COUNT (*)
      FROM stg_ser_level_inv_db a, map_stg_gsm_serv b
    WHERE a.account_number_v IN (SELECT account_number_v
                                    FROM map_transaction_number MAP
                                   WHERE MAP.trans_type_v IN ('F', '4'))
       AND a.trans_num_v
                        IN (SELECT trans_num_v
                              FROM map_transaction_number MAP
                             WHERE MAP.trans_type_v IN ('F', '4'))
       AND a.trans_type_v
                         IN (SELECT trans_type_v
                               FROM map_transaction_number MAP
                              WHERE MAP.trans_type_v IN ('F', '4'))
       AND a.acct_no = b.stg_account_number
       AND a.serv_account_number_v= b.stg_serv_link_code
       AND NOT EXISTS (
              SELECT 1
                FROM cb_sub_ar_ap ar
               WHERE ar.account_link_code_n = b.ab_serv_acc_link_code
                 AND ar.bill_cleared_flg_v = 'N'
                 AND ar.trans_num_v IN (SELECT target_trans_num_v
                                          FROM map_transaction_number MAP
                                         WHERE MAP.trans_type_v IN ('F', '4')))--3917why when u IN condition and join condition count is different. please let me know why?
    Thanks for advance ...
    Second :-2 Join Condition
    Total Count :-789948
    select COUNT(*)
        FROM STG_SER_LEVEL_INV_DB A , MAP_STG_GSM_SERV B,MAP_TRANSACTION_NUMBER ARAP_CUR
    WHERE  A.ACCOUNT_NUMBER_V = ARAP_CUR.ACCOUNT_NUMBER_V
    AND A.TRANS_NUM_V  = ARAP_CUR.TRANS_NUM_V
    AND A.TRANS_TYPE_V = ARAP_CUR.TRANS_TYPE_V
    AND A.ACCT_NO = B.STG_ACCOUNT_NUMBER
    and a.SERV_ACCOUNT_NUMBER_V  = B.STG_SERV_LINK_CODE
    and ARAP_CUR.TRANS_TYPE_V in ('F','4')
    and not exists (select 1 from CB_SUB_AR_AP ar
          where ar.account_link_code_n = B.AB_SERV_ACC_LINK_CODE
          and AR.BILL_CLEARED_FLG_V = 'N'
          and ar.trans_num_v = ARAP_CUR.TARGET_TRANS_NUM_V);---789948

    Hi,
    Whenever you have a problem, please post a complete test script that people can run to re-create the problem and test their ideas. Include a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data. In this case, data that produced no more than 10 rows of output for each query should be plenty.
    Simplify the problem as much as possible. For example, it looks like both your queries are joining tables a and b the same way. Why not pretend that you have only 1 table, ab, that is the same as the result set of joining a and b? Post CREATE TABLE and INSERT statements for the relevant columns of ab.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}
    There are several differences between those two queries.
    For one thing, Query 1 is doing a 2-way join between a and b, and then filtering that result set by comparing it to another table (let's call it map). So if a contains 5 rows and b contains 2 rows, the result set will contain at most 5 * 2 = 10 rows. Perhaps only 8 of those 10 rows will have matching rows in map. Note that the number of rows in map, or how many rows in map match rows in a or b doesn't matter. Query 2, on the other hand, is doing a 3-way join of a, b and map, so if map has 100 rows, the result set could have as many as
    (5 * 2) * 100 = 1000 rows. We know that it won't have that many rows, because only 8 out the rows from the a-b join have matching rows in map, but the result set of the 3-way join could still have as many as
    (8) * 100 = 800 rows.
    Since you didn't post test versions of your tables, I'll use tables from the scott schema to illustrate. Scott.dept has 4 rows, only 3 of which match rows in scott.emp, so
    SELECT  d.*
    FROM     scott.dept  d     -- tables a and b in your query play this role
    WHERE     d.deptno  IN (
                      SELECT  e.deptno
                   FROM     scott.emp  e     -- map plays this role in your query
    ;produces 3 rows of output. Exactly how many rows are in emp (that number happens to be 14) and how many of those rows match rows in dept (that happens to be 14, also) doesn't matter; all that matters in the query above is that 3 of the rows in dept have matches. However, the fact that 14 of the rows in emp have matches is important in the query bleow:
    SELECT     d.*
    FROM     scott.dept  d
    JOIN     scott.emp   e  ON  d.deptno  = e.deptno
    ;which produces 14 rows of output.
    Another differece is that Query 1 says that there are 3 conditions that relate table a to map; a given row in a will be included in the result set if any row in map meets condition 1, any row in map meets condition 2, and any row in map meets condition 3. It doesn';t matter if you have to look at 2 or 3 rows in map to meet all those conditions. Query 2 says that a row from a will be included only if there is a single row in map that meets all 3 conditions.

  • Query between two tables : COAS and BPGE

    Hi,
    I want to create a Query between tables : COAS and BPGE but when i generate the Info-set the system had a problem of jointure. (the field OBJNR exist in the both)
    By this query i want to display the Order and the value of Budget
    Please Advise
    Regards

    hi..
    you can go with following type of code....
    select  coas~field1
               coas~field2
               bpge~field5
               bpeg~field6
    from    coas inner/outer join bpge
      on     coasobjnr = bpgeobjnr
    into      table t_table
    where condition
    hope this one will solve the issue
    regards

  • Query to get number of invoice created by user between from and to date

    Dear All
    I need Query to get number of invoice created by user on day and his orgainization between from and to date.
    thanks

    select count(*) from ap_invoices_all where created_by = :p_User_id
    and trunc(creation_date) between :p_from_date and :P_to_date;
    Thanks/SRK

  • How to tune the query and difference between CBO AND RBO.. Which is good

    Hello Friends,
    Here are some questions I have pls reply back with complete description and url if any ..
    1)How Did you tune Query,
    2)What approach you take to tune query? Do you use Hints?
    3)Where did you tune the query and what are the issue with query?
    4)What is difference between RBO and CBO? where u use RBO and CBO.
    5)Give some information about hash join?
    6) Using explain plan how do u know where the bottle neck in query .. how u will identify where the bottle neck is from explain plan .
    thanks/Kumar

    Hi,
    kumar73 wrote:
    Hello Friends,
    Here are some questions I have pls reply back with complete description and url if any ..
    1)How Did you tune Query, Use EXPLAIN PLAN to see exactly where it is spending its time, and address those areas.
    See the forum FAQ
    SQL and PL/SQL FAQ
    "3. How to improve the performance of my query?"
    2)What approach you take to tune query? Do you use Hints?Hints can help.
    Even more helpful is writing the SQL efficiently (avoiding multiple scans of the same table, filtering early, using built-in rather than user-defined functions, ...), creating and using indexes, and, for large tables, partitioning.
    Table design can have a big impact on performace.
    Look for ways to do part of what you need before the query. This includes denormalizing (when appropriate), the kind of pre-digesting that often takes place in data warehouses, function-based indexes, and, starting in Oracle 11, virtual columns.
    3)Where did you tune the query and what are the issue with query?Either this question is a vague summary of the entire thread, or I don't understand it. Can you re-phrase this part?
    4)What is difference between RBO and CBO? where u use RBO and CBO.Basically, use RBO if you have Oracle 7 or earlier.

  • Ora-01847 day of month between 1 and last date of month coming in my query

    i m executing simple query but it is not working plz do help
    select *
    from sgvf_tree_nodes_vw
    where to_date(node_attr9_val, 'dd/mm/yyyy') between
    to_date('01/01/2010', 'dd/mm/yyyy') and
    to_date('31/12/2010', 'dd/mm/yyyy')
    gives : Ora-01847 day of month should be between 1 and last date of month

    Hi,
    Check the date format's once
    SQL> drop table demo;
    Table dropped.
    SQL> create table demo(val number, todate varchar2(12));
    Table created.
    SQL> insert into demo values(1,'04/11/2008');
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select * from demo;
           VAL TODATE
             1 04/11/2008
    SQL> select sysdate from dual;
    SYSDATE
    03-FEB-11
    SQL> insert into demo values(1,'04/11/2010');
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select *
      2  from demo
      3  where to_date(todate,'dd/mm/yyyy') between to_date('01/01/2010', 'dd/mm/yyyy') and to_date('31/12/2010', 'dd/m
    m/yyyy');
           VAL TODATE
             1 04/11/2010- Pavan Kumar N

  • QUERY DIFF BETWEEN CHECK AND IF

    Hi all,
    what is the difference between check and if.
    Which one is advisable to use in dialog program for field statment
    Thanks
    PREETI

    Hi,
    they work in different ways.
    IF..ENDIF.
    If u use "if .. endif" the program continues after the endif, and execute the code bewteen if and endif is the condition is fulfilled.
    CHECK
    If u use check, and if the condition is not fullfill, all the lines after the instructions will not be executed.
    With check instruction, un can exit from a form before the end of it.
    For example :
    form use_check using value.
    if value gt 0.
      value = value * 100.
    endif.
    endform.
    in this case u could use check.
    form use_check using value.
    check value gt 0.
    value = value * 100.
    endform.
    When use one instead of the other? depends on wich u have to do.
    Hope it helps
    Andrea
    Pls reward if it helps

  • What's difference between ASC and DESC index

    1 select count(*)
    2* from big_emp e where hiredate >= to_date('1980-01-01', 'YYYY-MM-DD') and hiredate <= to_date('1983-12-31', 'YYYY-MM-DD')
    COUNT(*)
    11971
    SQL> create index i_big_emp_hiredate on big_emp(hiredate);
    Index created.
    SQL> set autot trace
    SQL> select empno, ename, hiredate
    2 from big_emp e where hiredate >= to_date('1980-01-01', 'YYYY-MM-DD') and hiredate <= to_date('1983-12-31', 'YYYY-MM-DD') ;
    11971 rows selected.
    Execution Plan
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 11766 | 218K| 19 |
    |* 1 | TABLE ACCESS FULL| BIG_EMP | 11766 | 218K| 19 |
    SQL> drop index i_big_emp_hiredate;
    Index dropped.
    SQL> create index i_big_emp_hiredate on big_emp(hiredate desc);
    Index created.
    SQL> select empno, ename, hiredate
    2 from big_emp e where hiredate >= to_date('1980-01-01', 'YYYY-MM-DD') and hiredate <= to_date('1983-12-31', 'YYYY-MM-DD') ;
    11971 rows selected.
    Execution Plan
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 29 | 551 | 4 |
    | 1 | TABLE ACCESS BY INDEX ROWID| BIG_EMP | 29 | 551 | 4 |
    |* 2 | INDEX RANGE SCAN | I_BIG_EMP_HIREDATE | 53 | | 2 |
    i have 2 questions
    1. In "Expert one-on-one Oracle", Tom said, there is no deference between ASC and DESC index in case of one column because Oracle can just read in reverse order. but my test made me confused. why Oracle did "full table scan" only in ASC index???
    2. using "set autot trace" command. i believed the the "Rows" column mean the rows that Oracle access. Can you explain why the rows are 29(DESC) and 11766(ASC) in spite of the result is 11971. what is the exact meaning of "Rows" column in execution plan

    I think what you're seeing is a bug in the optimizer. If you had printed up the predicate section of the execution plan, this would be more obvious. I have the query:
    select *
    from   t1
    where  d1 between to_date('01-jan-2001')
              and     to_date('31-dec-2003')
    ;This returns one row per day for 3 years, and when a normal index is created on it, the optimizer calculates the correct cardinality and uses a sensible set of predicates. But when I use a descending index, this is what I get:
    Execution Plan
    Plan hash value: 1429545322
    | Id  | Operation                   | Name  | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT            |       |  1097 | 21940 |     2 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| T1    |  1097 | 21940 |     2 |
    |*  2 |   INDEX RANGE SCAN          | T1_I1 |     5 |       |     2 |
    Predicate Information (identified by operation id):
       2 - access(SYS_OP_DESCEND("D1")>=HEXTORAW('8798F3E0FEF8FEFAFF')  AND
                  SYS_OP_DESCEND("D1")<=HEXTORAW('879AFEF8FEF8FEFAFF') )
           filter(SYS_OP_UNDESCEND(SYS_OP_DESCEND("D1"))>=TO_DATE('2001-01-0
                  1 00:00:00', 'yyyy-mm-dd hh24:mi:ss') AND
                  SYS_OP_UNDESCEND(SYS_OP_DESCEND("D1"))<=TO_DATE('2003-12-31 00:00:00',
                  'yyyy-mm-dd hh24:mi:ss'))Note the introduction of the strange sys_op_descend() function - which is related to the descending index implemention, and the extra FILTER predicates which introduce a significant extra selectivity effect. The optimizer is double-counting on selectivity effects, and introducing extra factors of 1% and 5% (I haven't checked exact details) due to the functions applied to columns and the range-based predicates.
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    http://www.jlcomp.demon.co.uk

  • What is the difference between exists and in

    hi all
    if i have these queries
    1- select ename from emp where ename in ( select ename from emp where empno=10)
    and
    2- select ename from emp where exists ( select ename from emp where empno=10)
    what is the difference between exists and in is that only when i use in i have to bring the field name or what.... i mean in a complex SQL queries is it will give the same answer
    Thanks

    You get two entirely different result sets that may be the same. Haah! What do I mean by that.
    SQL> select table_name from user_tables;
    TABLE_NAME
    BAR
    FOO
    2 rows selected.
    SQL> select table_name from user_tables where table_name in (select table_name from user_tables where table_name = 'FOO');
    TABLE_NAME
    FOO
    1 row selected.
    SQL> select table_name from user_tables where exists(select table_name from user_tables where table_name = 'FOO');
    TABLE_NAME
    BAR
    FOO
    2 rows selected.So, why is this? the WHERE EXISTS means 'if the next is true', much like where 1=1 being always true and 1=2 being always false. In this case, where exists could be TRUE or FALSE, depending on the subquery.
    WHERE EXISTS can be useful for something like testing if we have data, without actually having to return columns.
    So, if you want to see if an employee exists you might say
    SELECT 1 FROM DUAL WHERE EXISTS( select * from emp where empid = 10);
    If there is a row in emp for empid=10, then you get back 1 from dual;
    This is what I call an 'optimistic' lookup because the WHERE EXISTS ends as soon as there is a hit. It does not care how many - only that at least one exists. It is optimistic because it will continue processing the table lookup until either it hits or reaches the end of the table - for a non-indexed query.

Maybe you are looking for