Select Max (date) between multiple tables

I need to retrieve a record from a Table in a set of similar tables with a common "date field". You can select the record where this "date field" value is greater between multiple tables.

Here, any help is appreciated.  Thank you in advance.

FOR EXAMPLE

No. EMP is the primary key.

Again, each table can have multiple records for EMP n ° 1

TABLE1:

FIRST NAME

FAMILY NAME
THE EMP NO.

BASE SALARY

DATE_FROM

TABLE 2

FIRST NAME

FAMILY NAME
THE EMP NO.

SALARY GRADE

DATE_FROM

TABLE 3

FIRST NAME

FAMILY NAME
THE EMP NO.

COMPENSATION

DATE_FROM

Hello

Said Knani, if you use the current design of the table, then here is a way to do what you want:

WITH union_data AS

(

SELECT MAX (base_salary) AS sal FROM table1 UNION ALL

SELECT MAX (grade_salary) table2 UNION ALL

SELECT MAX (compensation) FROM table3

)

SELECT MAX (sal) AS max_sal

Of union_data

;

Tags: Database

Similar Questions

  • Select Max (date) multiple records

    I'm having a problem getting the last value for several gauges.  Here's my query:

    SELECT parameter_id,

    TS_ID,

    value,

    Location_id,

    Date_Time

    Of

    MyTable

    JOIN IN-HOUSE

    mytable2

    WE

    TS_ID = ts_id

    WHERE

    TS_ID LIKE '% - rev.

    unit_id = ("pi")

    the value IS NOT NULL

    Location_id as "xxxx".

    Date_Time =

    (SELECT Max (date_time)

    My TABLE

    GROUP BY parameter_id)

    ;

    Hello

    A scalar subquery, such as the expression to the right of the sign =

    Date_Time = (SELECT...)

    must produce (at most) only 1 row.  If the subquery produces 2 or more lines, it will trigger an error.

    Given that you are using "GROUP BY parameter_id" in the subquery, it will produce a separate line of output for each distinct value of parameter_id.  You can use a correlated subquery at that time, that only looks like a parameter_id, or you can use a subquery IN, like this:

    WHERE (parameter_id, Date_Time) IN

    (

    SELECT parameter_id

    MAX (date_time)

    FROM MyTable

    GROUP BY parameter_id

    )

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and also publish outcomes from these data.
    Explain, using specific examples, how you get these results from these data.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002#9362002

  • Select all dates between two fields txt. How?

    In a slider form 6i, I need to select all dates between two dates provided. I have two fields text Fld1 and Chp2 with the data type date. There is no table behind the two fields.
    For example
    ': FLD1: = MARCH 1, 2013;
    ': CHP2: = MARCH 10, 2013;

    Now I have to choose all dates between 01-mar-2013 and 2013-mar-10 '. How to do?

    Gul says:
    In a slider form 6i, I need to select all dates between two dates provided. I have two fields text Fld1 and Chp2 with the data type date. There is no table behind the two fields.
    For example
    ': FLD1: = MARCH 1, 2013;
    ': CHP2: = MARCH 10, 2013;

    Now I have to choose all dates between 01-mar-2013 and 2013-mar-10 '. How to do?

    As'salamualikum Gul

    Try this

    SELECT TO_DATE('01-MAR-2013', 'DD-MON-RRRR') - 1 + rownum AS d
    FROM ALL_OBJECTS
    WHERE TO_DATE('01-MAR-2013', 'DD-MON-RRRR') - 1 + rownum BETWEEN TO_DATE('01-MAR-2013', 'DD-MON-RRRR') AND TO_DATE('10-MAR-2013', 'DD-MON-RRRR')
    

    Hope this helps

  • Select the data in a table and update in another table

    Dear experts,

    create the table TB_ENCRYPT

    (

    Identification number,

    Varchar2 (200) KEY

    );

    INSERT INTO TB_ENCRYPT VALUES(1,'HJUVHDUIFBSDGVU');

    SELECT * FROM TB_ENCRYPT;

    1 HJUVHDUIFBSDGVU

    create TABLE users)

    username, NUMBER of

    password VARCHAR2 (200)

    );

    Insert users

    values (1, 123 # "")

    Insert users

    values (2, 456 #')

    Select * from users;

    1 123 #.

    # 2 456

    I want to select the data KEY for table TB_ENCRYPT column and update in the column of tables for the respective key user password

    TB_ENCRYPT table contains only a single key value. Comparing this key, I want to update the old value of the key to the new value.

    For encryption and decryption I followed the java class method.no is worried about that.

    create or replace

    PACKAGE PCK_ENC AUTHID CURRENT_USER AS

    FUNCTION DECRYPT (VARCHAR arg0, arg1 VARCHAR) AS VARCHAR BACK LANGUAGE JAVA NAME 'Encrclass.decrypt (java.lang.String, java.lang.String) return java.lang.String ';

    FUNCTION ENCRYPT (VARCHAR arg0, arg1 VARCHAR) AS VARCHAR BACK LANGUAGE JAVA NAME 'Encrclass.encrypt (java.lang.String, java.lang.String) return java.lang.String ';

    END;

    SELECT PCK_ENC. ENCRYPT('1234','HJUVHDUIFBSDGVU') FROM DUAL;

    HERE,

    1234 - is the password of the users table column data

    HJUVHDUIFBSDGVU - represents the key of table TB_ENCRYPT column data.

    Comparing this key, I want to update the old value of the key to the new value.

    I tried with this method

    declare

    cursor c1 is

    Select the key

    of TB_ENCRYPT

    where id = 1

    update the id;

    Start

    for c1_rec looping c1

    update users

    password is PCK_ENC. Encrypt (Password, Key)

    the location being c1;

    commit;

    end loop;

    end;

    /

    Help, please

    You can use the MERGE statement.

    merge into users
    using tb_encrypt
       on (id = userid)
      when matched then
          update set password = PCK_ENC.ENCRYPT(password,key);
    

    And why you encrypt your password. This isn't a good idea. Just password hash.

  • Selection of data in the table in a table

    I use apex 3.2

    I have a report where he returnts say 3 rows.


    I need to select data from a table in and table and then use the data in this table in a body of email

    or select the data in the table and use the data in the body of the sub form of e-mail

    How can I do this. ?

    something like below

    Empno name e-mail address
    1 XX [email protected]
    2 bb [email protected]
    3 [email protected] aa

    Hello

    You can take the values in the table in the cursor and use it in the part of the email.
    It will be like,

    Cursor c1 is
    Select Empno, emp email;

    In the part of the body

    Hardcode the values of the columns inside html tags

    l_body: = '

    ';

    I'm in c1
    loop
    l_body: = l_body | »

    ';
    end loop;
    l_body: = l_body | »
    EmpNo
    i.EmpNoi.Namei.email
    ';

    then use the variable 'l_body' inside your share email.

    I hope this helps.

    Kind regards
    LIBERATOR

  • Synchronization of data between the tables of towing

    HII
    I have two database 1 and both of the databases of database 2 have citizen of table (citizen_ssn, citizen_name) with the same structure
    Ok

    and I create the link of database database 1 into database 2 (link name: link1)
    and I have another link for 2 to 1 of the databases database (link name: Link2)
    I want to synchronize data between two tables
    in other words, I want to when new record adds database1 go base2 and check if this folder exists (using citizen_ssn) or not, if it exists then add the record only in database1
    otherwise add record base1 and base2.

    and if there is record inserted into database 2, I'll go to database1 and check if it exists, it exists to add recording base2, if not add it in base1 and base2

    can I do this in real time or not.
    Thank you...

    I don't see how you have an infinite loop. If you insert a row into database1, the trigger will fire and verify the existence of the line of base2. If the line exists in base2, nothing happens. If the line does not exist, then a line will be inserted in base2, after what the relaxation in base2 fires that will check the existence of the line in database1 and, since it is, won't do anything.

    What Miss me?

    HTH
    Srini

  • Select Max (Date) in two different tables...

    Dear all,

    I need the date of last update of two different tables, I mean max (date). We will update one table at a time. Updated once I need to take the last update.

    It can be either in table A table B.

    for example.

    Table A

    Date of the ID

    100 16/05/2014

    101 20/05/2014

    102, 22/05/2014

    Table B

    Date of the ID

    100 04/06/2014

    101, 26/05/2014

    102 21/05/2014

    I need the date of table B (101 26/05/2014) last updated date...

    Hello

    Another way, using much more GRAND:

    SELECT LARGER (max1, max2) x

    FROM (SELECT MAX (mydate) max1

    OF mytable_a

    )

    (SELECT MAX (myotherdate) max2

    OF mytable_b

    )

    ;

    Best regards

    Bruno Vroman.

  • Create the form for selecting data in multiple tables

    Hello

    I'm getting APEX for the first time and I just read 2 days dev Application Express guide

    I tried to play and I can't create a report with the form that select data from several tables

    What I want to achieve is a report we'll say 'USERS' makes MANAGER_ID ID, NAME, with a form that allows me to create, delete, change users

    The problem is that, once the report with the form created, if I click on create (to create a user) it will ask me for id, name, and manager_id

    I need a water drop down which allows me to select managers in the table manager instead of manually insert Director id

    How do I do that?

    Thank you!

    HI Chris,

    LOV will use this magic.

    Search:

    Kind regards

    BEnjamin

  • data in multiple tables and columns

    Hello

    How to find if multiple tables are containing the same data?
    Text of the 'Apple' is in three different tables and under three different column names.
    Expected result
     
    fruits_one
    fruits_two 
    fruits_three
    Select name, quantity from fruits_one;
    Apple   1
    Orange  1
    Pear    1
    
    
    select flavour, desc from fruits_two;
    Red,   Apple 
    Blue, Berry
    
    select order,date,details  from fruits_three;
    101  11/11/2011    Grapes
    102  12/01/2010    Apple
    Thank you
    Sandy
    SQL> create table fruits_one (name varchar2(100), quantity number);
    
    Table created.
    
    SQL> insert into fruits_one
      2  select 'Apple'  name, 1 quantity from dual union all
      3  select 'orange'  name, 1 quantity from dual; 
    
    2 rows created.
    
    SQL> commit;
    
    Commit complete.
    
    SQL> create table fruits_two (flavour varchar2(100), des varchar2(100));
    
    Table created.
    
    SQL> insert into fruits_two
      2  select 'Red' flavour,   'Apple' des  from dual union all
      3  select 'blue' , 'berry'  from dual ;
    
    2 rows created.
    
    SQL> commit;
    
    Commit complete.
    
    SQL> set serveroutput on
    SQL> declare
      2  l_search varchar2(10) := 'APPLE';
      3  l_cnt number := 0;
      4  begin
      5
      6  for x in (select column_name, data_type, table_name from user_tab_cols where data_type in ('VAR
    CHAR2'))
      7  loop
      8
      9    execute immediate  'select count(*) from "' || x.table_name ||'" where upper("' || x.column_n
    ame || '") like ''%' || l_search || '%''' into l_cnt;
     10
     11    if l_cnt > 0  then
     12    dbms_output.put_line('table = "' || x.table_name ||'", column = "' || x.column_name ||'"');
     13    end if;
     14
     15  end loop;
     16
     17  end;
     18  /
    table = "FRUITS_ONE", column = "NAME"
    table = "FRUITS_TWO", column = "DES"
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    
  • Selection of data into a table

    Hello

    I'm trying to enter data in a table by using an instruction box to select the values of interest.

    The problem is this, I am under a for loop and every time that it runs, it reads a specific value in the table (table 1), using the for loop index as the index for table 1. So I check whether this specific value = preset value

    If Yes: the case statement writes the index in a table (table 2).

    If it is not: the case statement writes a constant - I would like to not have to do, but unfortunately the case loop must have all the input terminals connected.

    I would like the main table consist only of interest and no default values / values constant.

    Any ideas?

    You're abusing table to build.  Wire you a table in a table entry and other values or the other.  See the example I have attached.

  • Best approach to serve the same data between multiple users of the POJO DC

    Hello

    It is a question related to what is the best possible approach for this scenario.

    A POJO domain controller that retrieves a collection (of about 200 folders). The application displays the same records for all users of the application. The collection should be updated from time to time when there are new items and it must be visible to all users in DB.

    Currently, for each user that connects to the DC POJO application runs the query and deliver results. This works well when amount just a few users, but when multiple users want to access the app becomes very expensive.

    I think to build a programatically EO - VO, and then display it in a SharedApplicationModule where through the Cache of BC, I'll save and share data between users. I need to mark make a poll and update the collection when new results come thru.

    Is this a good approach? What are your thoughts or how would be better applied?

    Thank you very much.

    JDeveloper 12.c

    Hello

    Why do you use a POJO DC at all when the solution is to use a shared Module of Application ADF BC?  Sample 156 will become your friend:

    https://blogs.Oracle.com/smuenchadf/resource/examples#156

    Frank

  • Loading data from multiple tables in essbase using ODI

    Hello

    We have a scenario where the data comes from more than one table. I would like to know how ODI will load the data for the right combination of members

    Hello

    Consider each data table has a field that corresponds to the other table. You can simply drag the source interface data warehouses and create a join between the tables.

    See you soon

    John
    http://John-Goodwin.blogspot.com/

  • Sharing data between multiple while loops, competitor rates

    Hello

    I am trying to Exchange data between competitor while loops running at different speeds.  What is the recommended way to do this?    In practice, I have 12 indicators and 3 cards I would update (on screen) in the slower loop, although the data acquired and stored on disk in the fastest loop.  The image below is a simplified version of what really works my candidacy.

    I currently use local variables and shared to achieve this.  I heard however that local variables are evil because of their use of memory (data are copied instead of who passed by reference).

    Thanks for your suggestions,

    Adam

    Hi Adam,.

    Yes, here you go.

    Mike

  • Help the query to list all the days between MIN and MAX date in a table

    Hello

    Sorry, this may have already responded earlier, but I really struggled to find a previous response with the new provision of the RTO.

    In a DB 11 g, I date MIN and MAX in a table:

    {code}

    SELECT MIN (process_date) start_date, MAX (process_date) end_date FROM my_table;

    {code}

    I would get every day between these 2 dates. I mean even is there is no record in the table for a date.

    Is this possible?

    Thanks in advance,

    Olivier

    Hello

    Do you mean something like this?

    ranit@XE11GR2>> ed
    Wrote file c:\rb\1.sql
    
      1  with xx as
      2  (
      3      select
      4     to_date('05-06-2013','dd-mm-yyyy') min_d,
      5     to_date('20-06-2013','dd-mm-yyyy') max_d
      6      from dual
      7  )
      8  --
      9  -- end of test data
     10  --
     11  select
     12     min_d + level date_x
     13  from xx
     14* connect by level<=(max_d-min_d)
    ranit@XE11GR2>> /
    
    DATE_X
    -------------------
    06-06-2013 00:00:00
    07-06-2013 00:00:00
    08-06-2013 00:00:00
    09-06-2013 00:00:00
    10-06-2013 00:00:00
    11-06-2013 00:00:00
    12-06-2013 00:00:00
    13-06-2013 00:00:00
    14-06-2013 00:00:00
    15-06-2013 00:00:00
    16-06-2013 00:00:00
    17-06-2013 00:00:00
    18-06-2013 00:00:00
    19-06-2013 00:00:00
    20-06-2013 00:00:00
    
    15 rows selected.
    
  • DB connectivity Kit: syntax error in a SELECTION of data from joined tables

    Hello everyone

    I'm putting in labview a SQL query on joined tables.

    As an example I take a database to store the data of basketball 2on2 matches, which tables are

    corresponds to (matchId, Thomas, teamB)

    teams (teamId,PlayerAname, PlayerBname, nationality)

    nationalities (NatId, natName)

    To get an array of result with the game as well as the names of player as well as their nationality, I use this query on MySQL (which works on command line interface)

    SELECT MatchID,
    T1. PlayerAName, t1. PlayerBName, n1.natName,
    T2. PlayerAName, t2. PlayerBName, n2.natName
    MATCHES m
    INNER JOIN teams t1 ON t1.teamID = m.teamA
    INNER JOIN teams t2 ON t2.teamID = m.teamB
    INNER JOIN nationalities L1 ON n1.natID = t1.nationality
    INNER JOIN nationalities n2 ON n2.natID = t2.nationality

    When I put it in labview, using the block 'select data', I get a syntax error as shown in the attached screenshot.

    Am I something mistanking using the JOIN examples statements or aliases?

    Thanks in advance!

    The select VI is designed to be a simple way to select from a table. I doubt that he can do joins (and would not certainly need the 'FROM', even if it can). What you can do instead calls the query execute VI and give him the complete SQL query. I don't remember if it returns the data in the recordset object, so you must do so separately.

Maybe you are looking for