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.
Tags: Database
Similar Questions
-
I have the data into two table with the structure of similar column, I want to loop through the data in these two tables
based on some condition and runtime that I want to put the query in loop for example, the example is given, please help me
create table ab (a number, b varchar2 (20));
Insert into ab
Select rownum, rownum. "" sample "
of the double
connect by level < = 10
create table bc (a number, b varchar2 (20));
Insert into BC.
Select rownum + 1, rownum + 1 | "" sample "
of the double
connect by level < = 10
declare
l_statement varchar2 (2000);
Boolean bool;
Start
bool: = true;
If it is true, then
l_statement: =' select * ab ';
on the other
l_statement: =' select * from bc';
end if
I'm in execute immediate l_statement - something like that, but I don't know
loop
dbms_output.put_line (i.a);
end loop;
end;
Something like that, but this isn't a peace of the code work.
Try this and adapt according to your needs:
declare
l_statement varchar2 (2000);
c SYS_REFCURSOR;
l_a number;
l_b varchar2 (20);
Boolean bool;
Start
bool: = true;
If it is true, then
l_statement: = "select a, b, AB;
on the other
l_statement: = "select a, b from bc;
end if;
--
Open c for l_statement;
--
loop
extract the c in l_a, l_b;
When the output c % notfound;
dbms_output.put_line (l_a |') -' || l_b);
end loop;
close c;
end;
/
-
I have 2 tables, INVOICE and INVOICE_REFNUM similar to below. I'm writing a query that withdrawing the first date (less) for a single record remaining the two tables. Each table records the receipt of invoices, but according to the source of the received invoice some may reside in INVOICE_REFNUM and others the INVOICE table. I also use DECODE on the topic of INVOICE_SOURCE, when the date less is taken from the INVOICE table that contains that field, so if the date is in the field INVOICE_REFNUM DECODE is not necessary. Example:
INVOICE (table)
INVOICE_GID INVOICE_SOURCE INSERT_DATE
ABC. AVRT123 I HAVE 11/03/2012-15:49:32
ABC. CNWY234 G 12/03/2012 14:07:30
ABC. UPGF678 M 15/03/2012 20:21:54
INVOICE_REFNUM (table)
INVOICE_GID INVOICE_REFNUM_QUAL INVOICE_REFNUM_VALUE INSERT_DATE
ABC. AVRT123 SOURCE ACS 11/03/2012 14:49:32
ABC. CNWY234 SOURCE CSA 12/03/2012 13:07:30
ABC. UPGF678 SOURCE ACS 15/03/2012 21:21:54
My decode statement is: DECODE ("INVOICE_SOURCE, 'I', 'IDE', 'G', ' Auto-Pay", ', 'Manual')
If I were to write a query on these two tables, the output will resemble the following:
INVOICE_GID INVOICE_SOURCE INSERT_DATE
ABC. AVRT123 ACS 11/03/2012 14:49:32
ABC. CNWY234 ACS 12/03/2012 13:07:30
ABC. UPGF678 Manual 15/03/2012 20:21:54
I worked on it for 2 days, and I was able to pull a date by using the following SQL code, but cannot determine how to extract the corresponding source:
SELECT THE LEAST (GLOGOWNER. INVOICE_REFNUM. INSERT_DATE, GLOGOWNER. THE INVOICE. INSERT_DATE) AS 'DATE OF THE INVOICE.
GLOGOWNER. THE INVOICE. INVOICE_GID,
DECODE (GLOGOWNER. THE INVOICE. INVOICE_SOURCE, 'I', 'IDE', 'G', 'Auto-Pay', ', 'Manual').
GLOGOWNER. INVOICE_REFNUM. INVOICE_REFNUM_VALUE
OF GLOGOWNER. INVOICE
LEFT JOIN GLOGOWNER. INVOICE_REFNUM
ON GLOGOWNER. THE INVOICE. INVOICE_GID = GLOGOWNER. INVOICE_REFNUM. INVOICE_GID
WHERE GLOGOWNER. INVOICE_REFNUM. INVOICE_REFNUM_VALUE = "ACS."
AND GLOGOWNER. INVOICE_REFNUM. INVOICE_REFNUM_QUAL_GID = 'SOURCE '.
AND GLOGOWNER. THE INVOICE. INVOICE_TYPE = 'I '.
ORDER OF GLOGOWNER. THE INVOICE. INVOICE_GID
Any help is greatly appreciated!
Best regards
-Adam
Hello
Is that what you want?
SELECT i.invoice_gid
CASE
WHEN ir.insert_date<= i.insert_date ="" then ="">=>
WHEN i.invoice_souce = 'I' and THEN 'EDI '.
WHEN i.invoice_souce = 'G' THEN 'debit '.
WHEN i.invoice_souce = am' THEN 'manual '.
END AS invoice_source
, The LEAST (i.insert_date, ir.insert_date) AS insert_date
I have the Bill OF
JOIN invoice_refnum ON i.invoice_gid = ir.invoice_gid ir
WHERE ir.invoice_refnum_value = 'ACS '.
AND ir.invoice_refnum_qual_gid = 'SOURCE '.
AND i.invoice_type = 'I '.
ORDER BY i.invoice_gid
;
There is no reason to do an outer join if you only want the lines with specific values anyway.
What happens if the 2 tables have exactly the same invoice_date? The query above takes the invoice_source of invoice_refnum in this case, but that can easily be changed.
Or the other of the insert_dates can be NULL?
I hope that answers your question.
Otherwise, thank you post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also after the results you want from these data (otherwise what you have already posted).
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
-
Generate the command Id and insert data into two different tables: oracle apex 5.0
I have three tables. name of the tables: PRODUCT, ORDER_HEADER, ORDER_DETAIL. I took REPORT inter ASSETS in which the VALUES from TABLE product. I need to use the trigger here, there is a TEXT ARTICLE called ORDER ID: it will generate through trigger. so whenever new order placed order id must be unique. There is a button when this button is clicked, the VALUES of REPORT must be inserted in to ORDER_HEADER , ORDER_DETAIL (in fact, I am in confusion is it even possible).
I tried to create the trigger: not work if
CREATE OR REPLACE TRIGGER "EMP_TRG1".
Before Insert on order_header
for each line
Start
If: new. Order_ID is null
then
Select lpad (demo_seq.nextval, 8, '0'): new. Order_ID order_header;
end if;
end;
SQL:
Select
apex_item. Text(1,p.PRODUCT_ID) PID.
PN.product_name,
apex_item. Text(2,p.PRODUCT_QTY) qt.
apex_item. Text(3,p.unit_price) upward,
apex_item. Text(4,p.TOTAL_AMOUNT) am
OMS_SHIP_CART_DETAIL p, pn OMS_PRODUCT
where p.product_id = pn.product_id
DA:
var arr_f01 = [];
var arr_f02 = [];
var arr_f03 = [];
var arr_f04 = [];
var arr_f05 = [];
product_id var;
unit_price var;
Var Qty;
var total_1;
() $("input[name='f01']").each
function() {}
product_id = $(this).closest('tr') .children ('td [headers = 'PID']') .text ();
unit_price = $(this).closest('tr') .children ('td [headers = "Uprice"]') .text ();
Qty = $(this).closest('tr') .children ('td [headers = "Qty"]') .text ();
total_1 = $(this). Closest ('tr'). Children ('td [headers = "total"]'). Text();
arr_f01.push ($(this).) Val());
arr_f02.push (product_id);
arr_f03.push (total_1);
arr_f04.push (unit_price);
arr_f05.push (Qty);
} );
(apex). Server.Process
"Insert a command."
, {f01: arr_f01, f02: arr_f02, f03: arr_f03, f04: arr_f04, f05: arr_f05}
}
, {dataType: "text", success: function (pData) {alert ('added product') ;}}
);
Ajax callback:
declare
l_count number;
Start
-insert into OMS_ORDER_HEADER (USER_ID, TOTAL_AMOUNT, batch, ORDER_DATE) values(:P1_USER_ID,:P42_TOTAL,'PENDING',SYSDATE);
I'm looping 1.apex_application.g_f01.count
insert into OMS_ORDER_DETAIL (PRODUCT_ID, UNIT_QTY, UNIT_PRICE, TOTAL_AMOUNT)
values (APEX_APPLICATION. G_F01 (i), APEX_APPLICATION. G_F03 (i), APEX_APPLICATION. G_F04 (i), APEX_APPLICATION. G_F05 (i));
commit;
end loop;
end;
Hi Dominique,.
I create a process page away present in your application
declare l_order_id varchar2(8); begin insert into order_header(ORDER_ID , STATUS , ORDER_DATE) values(lpad(demo_seq.nextval,8,'0') , 'Pending' , sysdate) returning ORDER_ID into l_order_id; for rec in(select ID , QTY , PRICE from product) loop Insert Into Order_Detail ( ORDER_ID , PRODUCT_ID , QTY , UNIT_PRICE) Values(l_order_id , rec.id , rec.qty , rec.price); commit; end loop; end;
Please check and let me know.
Kind regards
Jitendra
-
Process in two different tables in one page
Hi all
I have A form with a submit button, when I click on the button I want to send the data from two different tables. For example:
REQ_ID: 221
BOX_NUMBER: 2
NOM_ELEMENT: APPLE
COUNTRY_ORIGIN: USA
I want to send all the information in table 1 and only REQ_ID and BOX_NUMBER in table 2.
I tried to create processes two different which are:
1. the usual process line DML for table 1 and;
2. simple query 'Insert' SQL for table 2
It seems fine, until I realized that when the user tries to update the BOX_NUMBER to 10 for example, only 1 table is updated and table 2 creates an another duplicate data instead of updating the old one! This also applies to my button Delete,.
any idea to fix this problem?
Thank you very much
Vika
Reread what you wrote and you would realize why 2nd table only "new lines".
2. simple query "Insert into ' SQL for table 2
If you need to UPDATE the table, then you must write a simple UPDATE statement.
If you want to REMOVE from the table, then you must write a simple DELETE statement.
I call this "DML DIY" - do it yourself DML
(personally, I'd probably use MERGE for INSERT and UPDATE)
MK
-
To find common data in 2 columns from two different tables.
Hello
Could someone help me with a querry to discover common data of 2 columns from two different tables?
Thank you
RajeshTry as below.
select col1 ,col2 from tab1 intersect select col1 ,col2 from tab2;
-
Insertion of records in two different tables at the same time?
Hello everyone, I have question about inserting records in two different tables at the same time, I'm looking for is by the way a unique id, which is created in the first statement insert to the second insert statement. Example of this problem:
< cfquery name = "addRecords1" datasource = 'test' >
Insert Into Table1 (name, Date, age)
Values (< cfqueryparam cfsqltype = "cf_sql_char" value = "#arguments.) "Name # ' >.
< cfqueryparam cfsqltype = 'cf_sql_date' value = '#arguments. "Date # ' >.
< cfqueryparam cfsqltype = "cf_sql_int" value = "#arguments. Age #"(>); "
Select SCOPE_IDENTITY() as RecID;
< / cfquery >
< cfquery name = "addRecords2" datasource = 'test' >
Insert into Table2(Company,City,Date,ID)
Values (< cfqueryparam cfsqltype = "cf_sql_char" value = "#arguments.Company #" >,)
< cfqueryparam cfsqltype = "cf_sql_char" value = "" #City # ">,"
< cfqueryparam cfsqltype = 'cf_sql_date' value = "" #Date # ">,"
( < cfqueryparam cfsqltype = "cf_sql_int" value = "How to pass RecID to insert in this table?" >).
< / cfquery >
In this example, I'm inserting records in table 1 and creation of IDENTITY SCOPE as RecId. I would like to pass this id and insert it in my table 2. This Id, I'll use in my second table as an identifier. If anyone knows anything about this please let me know. Thank you.
); QueryName - DOT - ColumnName, so it should be:
); HTH,
^_^
-
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
-
extraction of unique records of registration of two different tables
Hello
In the following two tables different www.testing.com code exists in both tables. I want to compare two different columns from two different tables for unique records.
Thank you and best regardsSQL> select unique(videoLinks) from saVideos where sa_id=21; VIDEOLINKS ----------------------------------------------------------------------- www.testing.com SQL> ed Wrote file afiedt.buf 1* select unique(picLinks) from saImages where sa_id=21 SQL> / PICLINKS ----------------------------------------------------------------------- test test14 www.hello.com www.testing.com
Try
Select unique (videoLinks) in the saVideos where sa_id = 21
Union
Select unique (picLinks) in the saImages where sa_id = 21 -
How to get into two different tables in two columns of a listbox of multi column
Hi all
I have two different tables of the values assume that table 1A (1,2,3,4,5) and another table B (3,4,5,6,7). I want to write these tables in a multicolumn listbox such as 1st column would be A array and 2nd column table B.
Thnx in advance
Saki,
I hope this helps to further
-
How to get data in two different bases?
Hello guys!
I want to retrieve data from two different databases. I can't use one because they are in different cities, and now I need to use both. How can I do?
Thank you!
Published by: Tipertuba on 11/11/2009 05:13Use the links in DB, if everything you do is querying the data... if its replication in time more real then look in or data streams keep... but below you can find things on the database link
http://www.morganslibrary.org/reference/Db_link.html
-
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
;
-
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
-
The selection of two different tables when a value is null or zero in one
Hi friends,
I have two tables where the data of...
so now I have to display the value of tab1.value and if the value that it is) or null I should poster from another table viceversa
tab1. Value 100 tab2.value 0
now I get the value of tab1.value
tab1. Value null tab2.value 200
now, I should get the value of tab2.value
If tab1.value is 0 and tab2.value is 0 then display 0
How to do this
Thank youselect prrv.result_value, pg.attribute3, case when prrv.result_value is null or prrv.result_value = 0 then pg.attribute3, else prrv.result_value end from per_grades pg,pay_run_results prrv where prrv.id=pg.id /
SY.
-
Hello
I am trying to build a query WITH, but I can't seem to make it work:
WITH P1 AS (SELECT OT_VALUE
OF CSD_OPEN_VERY_HIGH_INCIDENTS VHIGH
WHERE OT_VALUE > = 0
). P2 AS (SELECT OT_VALUE
OF HIGH CSD_OPEN_HIGH_INCIDENTS
WHERE OT_VALUE > = 0
), SELECT VHIGH. OT_VALUE, TOP. OT_VALUE
P1 P2 JOIN INTERNALLY. RATING = P2. RANKING
The two tables have the same column names.
I want to only return a set of results if the two columns (OT_VALUE) contain in reality 1.
Select this check box. This is a job for all four images. This will return the line to the following combinations. 0.0 and 0.1 and 1.0 and 1.1. Importance is 1.2. Let me know if you face any problem
SELECT CASE WHEN ((VH_OT_VAL = 0 ET H_OT_VAL = 0) OR (VH_OT_VAL = 1 AND H_OT_VAL = 0) OR (VH_OT_VAL = 0 AND H_OT_VAL = 1) or (VH_OT_VAL = 1 AND H_OT_VAL = 1)) 1
ANOTHER ACE OF NULL TERMINATOR OT_VAL
DE)
SELECT H.OT_VALUE H_OT_VAL,
VH. OT_VALUE VH_OT_VAL
OF CSD_OPEN_VERY_HIGH_INCIDENTS VH.
CSD_OPEN_HIGH_INCIDENTS H
WHERE NVL (VH. CLASSIFICATION, 0) = NVL(H.CLASSIFICATION,0)
AND VH. IMPORTANCE IN (1,2)
AND H.IMPORTANCE IN (1,2)
AND NVL (VH. OT_GROUP, 0) = NVL(H.OT_GROUP,0)
AND VH. IMPORTANCE = H.IMPORTANCE
AND VH. TIME_STAMP = H.TIME_STAMP
);
Maybe you are looking for
-
question to iCloud with El Capitan
I searched but could not find a relevant answer. I recently did a wipe on my Macbook air and clean installed El Capitan. But every time he asks me a different password of my iCloud. When I got to the control panel user account and click on chan
-
Re: Installing Win7 on Satellite C50-A628
Whenever I want to install 'Windows 7' show the message *. 'Load the driver. A required CD/DVD drive device driver is missing. If you have a driver disk, CD, DVD, or USB flash drive, please insert it now. Note: If the Windows installation media is in
-
How to add friends This message was transferred from its previous location to create his own new topic here; his subject and/or the title has been changed to differentiate the position of other requests for information and to reflect the content of t
-
Need driver driver drive HARD IDE - USB 2.0 charger bridge on P30
Hi all 2 days ago, I bought an external HARD drive 2.5 (BUFFALO HD USB2 & USB1-PHGU2/UC). When I plug it into my USB port on my P30, XP has found a new material and try to install it, but it can't find the driver (CHARGER IDE HARD drive - USB2.0 Brid
-
Is there a way to EZ to activate plugins on MacBook
I have an old Mac and I try to use Netflix. Tried to install Silverlight and it seems impossible. Trying to not give up. My plugins is disabled and I can't understand how to activate it. Talked to everyone and no. seems to know. Hate paying Apple mor