How to select Max in a multi query?

Hi all,
I got this query:
select DEPTNO, EMPNO from EMP1 minus select DEPTNO, EMPNO from EMP2;
I want to get single row from the results of this query, so I may use MAX or MIN or where rownum<2.
How can I do this please....
I tried: SELECT MAX(select DEPTNO, EMPNO from EMP1 minus select DEPTNO, EMPNO from EMP2) from DUAL;
but I got syntax error :(
Please help....
Thanks

select DEPTNO, EMPNO from EMP1 minus select DEPTNO, EMPNO from EMP2;
I want to get single row from the results of this querywhich row is correct row & why?
How many rows returned now? (Since we don't have your tables or data.)
Handle:      KinsaKaUy?
Status Level:      Newbie
Registered:      Mar 9, 2011
Total Posts:      614
Total Questions:      168 (110 unresolved)
so many questions & so few answers.
How SAD!
Edited by: sb92075 on Aug 29, 2011 11:10 AM

Similar Messages

  • How to : SELECT MAX(EmpID) / count(*) in SELECT Query

    Hi,
    I like to find out the Maximum of the EmpID that is in the DB table.
    So I need to perform a select Query:
    Select MAX(EmpID) from EmpTable
    or Select Count(*) from EmpTable
    <StatementName>
    <dbTableName action=”SELECT”>
       <table>realDbTableName</table>
         <access>
             <??? />
          </access>
    </dbTableName> 
    </StatementName>
    I cannot type MAX(EmpID) or count(*) as access element
    So what should I mention in the Access?
    Thanks & regards,
    Siva Maranani.

    if 0CALDAY is used as a characteristic then you have to convert that as a key figure using a replacement path variable.
    Please see the below link for changing 0CALDAY as a key figure using Replacement path
    http://www.sd-solutions.com/documents/SDS_BW_Replacement%20Path%20Variables.html
    https://websmp106.sap-ag.de/~sapdownload/011000358700001963972003E/HowToCalcWithAttr.pdf
    Now you have to create an exception "Top N Rows" based on the replacement path variable created above.
    This will solve your problem.
    Regs
    Gopi.
    Award points if it helps ...

  • How to select max (field) and one more field from table?

    Hi experts!
    I need to select maximum value of ENDDA from PA0023 and BRANC of max ENDDA.
    How can I do that ?
    When I trying this code:
    This is the  code:
    SELECT MAX( endda ) branc
      FROM pa0023
      INTO (pa0023-endda, pa0023-branc).
    I get error message:
    The field "PA0023~BRANC" from the SELECT list is missing
    in the GROUP BY clause. Addition INTO wa or INTO (g1,...,gn)  is required.
    So what is the problem?
    Thanks forehead.

    Hi
    Though am not totally sure of your requirement, check below code samples without any syntax errors:
    1. As per you current coding:
    TABLES: pa0023.
    SELECT MAX( endda ) branc
           FROM pa0023
           INTO (pa0023-endda, pa0023-branc)
           GROUP BY branc.
    ENDSELECT.
    2. Above code results only on one record where as the criteria can be more than one. Eg: for a specific data more than one record can exist. Below code helps you handle the same:
    TABLES: pa0023.
    TYPES: BEGIN OF t_pa0023,
             endda TYPE endda,
             branc TYPE brsch,
           END OF t_pa0023.
    DATA: i_pa0023 TYPE TABLE OF t_pa0023,
          wa_pa0023 TYPE t_pa0023.
    SELECT MAX( endda ) branc
           FROM pa0023
           INTO TABLE i_pa0023
           GROUP BY branc.
    LOOP AT i_pa0023 INTO wa_pa0023.
    ENDLOOP.
    3. If the requirement is to get the Industry Key for the record with highest End Date. We can acheive it by using subquery something like:
    TABLES: pa0023.
    SELECT SINGLE endda branc
           FROM pa0023
           INTO (pa0023-endda, pa0023-branc)
           WHERE endda = ( SELECT MAX( endda ) FROM pa0023 ).
    Kind Regards
    Eswar

  • How to select max total marks from a student tab

    SQL> select st_id max(sum(stu_marks))
    2 from stu_marks;
    select st_id max(sum(stu_marks))
    ERROR at line 1:
    ORA-00923: FROM keyword not found where expected
    thanks

    select st_id,sum(stu_marks) Marks
    from stu_marks
    group by st_id
    but if you just want the highest mark try:
    select st_id,sum(stu_marks) marks
    from students
    group by st_id
    having sum(st_marks) =
    ( select max(sum(st_marks)) from students group by st_id)

  • Prompt filters, how to select by name, but do query by Id?

    Hi,
    I have a prompt list, I'm displaying the names of the values, but I want to query by Id, is that possible? My query is taking too much time, because it's comparing the names.
    For example I have:
    Name    Id
    John      23
    Mary      25
    Tom       28
    etc...
    In the prompt list I have the names (John, Mary, Tom,etc) I want to keep these name in the prompt list, but in the query I want to compare by Id.
    Thanks,
    Marcela

    Hi Arm,
    Thanks for responding.
    I'm not getting the data.
    I have Country_Code and Country_Name, I changed Country_Code dimension in the Edit tab, I added Country_Name in Country_Code.
    Then I changed the prompt filter to use Coutry_Code like this:
    @Select(Country Region\Country Code) IN @Prompt('1b.Enter the country','A','Country Region\Country Code',Multi,Constrained) OR 'ALL' IN @Prompt('1b.Enter the country','A','Country Region\Country Code',Multi,Constrained)
    But in the query I'm getting:
    AND
       ( ( COUNTRY_CODE ) IN ('Australia','Brazil','Costa Rica') OR 'ALL' IN ('Australia','Brazil','Costa Rica'))
    I'm not getting the data because those are Country_Names not Country_codes.
    Any idea?
    Thanks,
    Marcela

  • Who to select max total marks of a student from a stu_marks tale;

    how to select max total marks from a student tab
    Posted: Feb 1, 2007 5:25 AM Reply
    SQL> select st_id max(sum(stu_marks))
    2 from stu_marks;
    select st_id max(sum(stu_marks))
    ERROR at line 1:
    ORA-00923: FROM keyword not found where expected
    thanks

    SQL> with t as (SELECT st_id,
      2                    sum(stu_marks) total_marks
      3             FROM stu_marks
      4             GROUP BY st_id)
      5  select t.st_id, t.total_marks
      6  from t
      7  where t.total_marks = (select max(total_marks)
      8                         from t)
      9  /
         ST_ID TOTAL_MARKS
             2         210
    1 row selected.
    SQL>Cheers
    Sarma.

  • How to use select max and min query..

    hi gurus,
    we have got a custom report for develoment.
    the report has to fetch the max and min salarys department wise....
    how to pick up max & min sal ansal from table pa0008.

    Hi,
    Try the following
    select max(sal)
               min(sal)
               from <database table>
               into <internal table>
               group by department
               where <where condition>.
    Here we assume that sal is the field holding the salary and department is the name of the field in the database table. Where condition is optional.
    Hope this helps.
    Regards,
    Sachin

  • How to select a value of a max value of another column in the same row?

    pversion pdate pcount
    1     11/6/2011     1
    0     11/6/2011     25
    1     11/6/2011     24
    How to select pversion for a maximum pcount, in this case max count is 25 and version will be 0?

    Like this?
    -- Data:
    with yourtable as
    select 1 pversion , 1 pcount from dual union all
    select 0 , 25 from dual union all
    select 1 , 24 from dual
    -- Query:
    select max(pversion ) keep (dense_rank last order by pcount) m_pversion
    from yourtable;(When you want to use the query with your real data, you will have to change 'yourtable' to your actual tablename)

  • How to select the max rowid from a subquery with group by

    Hi Gurus,
    Kindly help how to fix the following query because I'm getting Oracle error:ORA-01446.
    select * from edy_raw_data a
    where rowid in ( select max(rowid) from(
    select email,max(date_updated) from edy_raw_data b
    where b.email=a.email
    group by email ))
    The query select the max rowid from a sub query with group by.
    Thanks in Advance.
    Benjie

    Why do you need to compare with rowid?
    Wouldn't this suffice?
    select * from edy_raw_data a
    where (email,date_updated) = (select email, max(date_updated) from edy_raw_data b
                        where b.email=a.email
                        group by b.email ))* Note: untested

  • How to get min,max,avg time for query execution?

    Dear Friends,
    In AWR we are getting avg time taken to execute particular query, how can one get min,max time taken by query during number of executions.
    Thanks

    I would run the sql in a cursor for loop, to get a quite reasonable execution time without changing the actual execution plan:
    SQL> show user;
    USER is "HR"
    SQL> set timing on
    SQL> select count(*) from all_objects;
      COUNT(*)
         55565
    Elapsed: 00:00:03.91
    SQL> var p_sql varchar2(200)
    SQL> exec :p_sql := 'select * from all_objects'
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.00
    SQL> declare
      2  t1 timestamp := systimestamp;
      3  begin
      4    execute immediate 'begin for c in (' || :p_sql || ') loop null; end loop; end;';
      5    dbms_output.put_line('Elapsed: ' || (systimestamp - t1));
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:03.53
    SQL> declare
      2  t1 timestamp := systimestamp;
      3  begin
      4    execute immediate 'begin for c in (' || :p_sql || ') loop null; end loop; end;';
      5    dbms_output.put_line('Elapsed: ' || (systimestamp - t1));
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:02.75
    SQL> declare
      2  t1 timestamp := systimestamp;
      3  begin
      4    execute immediate 'begin for c in (' || :p_sql || ') loop null; end loop; end;';
      5    dbms_output.put_line('Elapsed: ' || (systimestamp - t1));
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:02.73
    SQL> declare
      2  t1 timestamp := systimestamp;
      3  begin
      4    execute immediate 'begin for c in (' || :p_sql || ') loop null; end loop; end;';
      5    dbms_output.put_line('Elapsed: ' || (systimestamp - t1));
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:02.66
    SQL> ---- alter system flush shared_pool;
    SQL> declare
      2  t1 timestamp := systimestamp;
      3  begin
      4    execute immediate 'begin for c in (' || :p_sql || ') loop null; end loop; end;';
      5    dbms_output.put_line('Elapsed: ' || (systimestamp - t1));
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:02.80
    SQL> declare
      2  t1 timestamp := systimestamp;
      3  begin
      4    execute immediate 'begin for c in (' || :p_sql || ') loop null; end loop; end;';
      5    dbms_output.put_line('Elapsed: ' || (systimestamp - t1));
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:02.64
    SQL>
    https://forums.oracle.com/thread/705536?start=15&tstart=0
    Regards
    Girish Sharma

  • How do I print selected pages from a multi page document

    How do I print selected pages from a multi page document?
    This question was solved.
    View Solution.

    Hi,
    It depends on the software you are using, what is it ? In general you can select a range or just a number of pages.
    Regards
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • SQL query problem - select max (case... aggregate function)

    Hi,
    I have a problem with below sql query, it gives me problem/error message 'ORA-00937: not a single-group group function', why?
    select sag.afdeling, sag.sagsnr, to_char(sag.start_dato, 'yyyy-mm-dd'), sag.stat, BOGF_TRANS.TRANSTYPE,
    max (case when BOGF_TRANS.TRANSTYPE = 'K' then sum(bogf_trans.belobdkk) end) + -- as "TRANSTYPE K",
    max (case when BOGF_TRANS.TRANSTYPE = 'D' then sum(bogf_trans.belobdkk) end) as "TRANSTYPE K & D",
    max (case when BOGF_TRANS.TRANSTYPE = 'S' then sum(bogf_trans.belobdkk) end) as "SUM TRANSTYPE S"
    from sag
    join bogf_trans on sag.selskab = bogf_trans.selskab and sag.sagsnr = bogf_trans.sagsnr and sag.afdeling = bogf_trans.afdeling
    where SAG.SELSKAB=37 and SAG.AFDELING = 'SUS' AND SAG.SAGSNR = 10876
    group by sag.afdeling, sag.sagsnr, sag.start_dato, sag.stat, BOGF_TRANS.TRANSTYPE
    If I exclude (columns) as below it give me correct summations (max (case... sum(...)) but then I miss some important info that I need
    select
    max (case when BOGF_TRANS.TRANSTYPE = 'K' then sum(bogf_trans.belobdkk) end) + -- as "TRANSTYPE K",
    max (case when BOGF_TRANS.TRANSTYPE = 'D' then sum(bogf_trans.belobdkk) end) as "TRANSTYPE K & D",
    max (case when BOGF_TRANS.TRANSTYPE = 'S' then sum(bogf_trans.belobdkk) end) as "SUM TRANSTYPE S"
    from sag
    join bogf_trans on sag.selskab = bogf_trans.selskab and sag.sagsnr = bogf_trans.sagsnr and sag.afdeling = bogf_trans.afdeling
    where SAG.SELSKAB=37 and SAG.AFDELING = 'SUS' AND SAG.SAGSNR = 10876
    group by sag.afdeling, sag.sagsnr, sag.start_dato, sag.stat, BOGF_TRANS.TRANSTYPE
    Any ideas?

    Moved to more sutable forum, sorry.

  • How to set the default selection to "Select All" in a Multi valued parameter in SSRS 2008?

    Hello Everyone,
    How to set the default selection  to "Select All" in a Multi valued parameter in SSRS 2008?
    Regards
    Gautam S
    Regards

    You need to specify "Default Values" in the report parameter property. Choose similar option used in the "Available Values" option, this will allow the parameter to check "Select All".
    Regards, RSingh

  • How to get max date in variable using  dynamic query

    Hi,
    the following code gets all dates from sourcetable i want only max date , so i thought max function can be added and it will work
    but still i have to create a table for one value(scalar) can get it in any other effeciant way.
    declare
    TYPE date_string IS TABLE OF VARCHAR(1000);
    date_obj date_string;
    BEGIN
    EXECUTE IMMEDIATE 'SELECT to_char('''||day1||'-'||month1||'-'||year1||''') FROM '||source_schema||'.'|| sourcetable ||'' bulk collect INTO date_obj;
    FOR indx IN date_obj.FIRST..date_obj.LAST loop
    dbms_output.put_line(
    date_obj(indx));
    END loop;
    DBMS_OUTPUT.PUT_LINE('Sample output');
    END;
    yours sincerely

    944768 wrote:
    the following code gets all dates from sourcetableNo it doesn't. What is the datatype of day1, month1 and year1? They cannot be DATE datatypes otherwise your TO_CHAR would fail with all that concatenation going on. And your TO_CHAR is returning a VARCHAR2 datatype... so you cannot say that it is getting all dates... because there are no DATE datatypes returned. It's getting a lot of strings, but certainly not DATE's.
    i want only max date , so i thought max function can be added and it will work You can use the MAX function on a DATE datatype, but not on strings (at least not in the way you intend it to work).
    Converting it to a DATE before doing the MAX will allow you to get the maximum date (assuming the date format is correct)
    EXECUTE IMMEDIATE 'SELECT max(to_date(to_char('''||day1||'-'||month1||'-'||year1||'''),''DD-MM-YYYY'')) FROM  '||source_schema||'.'|| sourcetable ||'' bulk collect INTO date_obj;Then you will find have the other issues...
    a) you are then going to be fetching your DATEs in to a collection of VARCHAR strings. (Not even VARCHAR2, very poor). This should be DATE datatype
    b) you are bulk collecting into a collection, when you are using MAX which will return a single value in your example
    And you really should address the design issues:
    c) why are day, month and year, not being stored in the database as a single DATE datatype in the first place
    d) why does your code not know the name of the table it's querying requiring the use of very poor dynamic SQL techniques.
    e) why are you loading data in a collection in expensive PGA memory... what can't you do in SQL that requires you to collect the data into memory first?

  • How to Select More then 1000 values in Multi-Select prompt!!!

    Hello Users,
    I have Scenario where i have to pass all the values from prompt to report and the values in the prompt are coming from session variable, so whatever value access user has the report will run with that only...
    Now the question is that Multi-Select Prompt is not able to take more then certain values, so is there any way that we can increase the limit for selected values??
    in-short how to increase the limit for selected values in multi-select prompt??
    Thanks In Advance!!!

    Hey David,
    The Scenario is like, we have data level security on "Unit" attribute. now based on the user selection when user logs in he should able to see the report only for those units which he/she has access.
    in total we have 1800 units available, now for 5-10 units access is fine, but the question will arise when user will not have only some units access from 1800 units.
    because report will not take those values from the multi-select prompt reason is that multi-select prompt is not able to take more then certain values in selected side.
    now in multi-select until-unless u have data coming in selected side those values will not pass. so i have kept the sql in default for that prompt.
    so when user logs in he will able to see those values in selected side for the multi-select prompt, but when values increase from some level it's going automatically in un-selected side.
    i want everything on selected side of multi-select prompt.
    Let me know if you need any further details.

Maybe you are looking for

  • A better way to execute a series of external commands?

    Hi, Consider the code snippet... Process proc1 = rt.exec("Some external command"); Vector vecOutput = outputGobbler.getOutput() ; String[] strAlterCmds = new String[vecOutput.size()]; for ( int k = 0 ; k < vecOutput.size() ; k++ ) strAlterCmds[k] = n

  • User login with details

    hi guys, was need to come out a report for the user login details. which has to have the date and time of the user login to SAP, with the terminal ID access from and transaction has done. can any one tell me what table it is from? or is there existin

  • Slideshow Labeling Options in iPhoto vs. iDVD?

    Hi all, Are there any enhancements to putting onscreen labels for slideshows (i.e., visible during playback)? All I've been able to find is the ability to "show title" in iPhoto (no font choice, extreme corner of screen) and a bottom-of-screen option

  • Errors during CS6 update

    After software download and update Adobe Application Manager gives the following errors: Touch App Plugin Update Installation failed. Error Code: U44M1P7 DPS Desktop Tools CS6 2.05.1 Update There was an error installing this update. Please quit and t

  • Composite vat calculation

    Hi friends,        i have a one requirement we are using one line item for vat calculation and second line item for service tax calculation in sales order suppose 100Rs material price and 20Rs labor cost now we are using VAT calculation 5% on Materia