SQL & PL/SQL :: Select Records Where Date Is Max From Tables

Oct 6, 2011

I've got 3 tables and I need to select records where date is max from these tables.

select * from the_table_1
----------------------------------
contract_key date_1 saldo
1234 30.9.2011 12:06:50 14,6638

select * from the_table_2
----------------------------------
contract_key date_1 saldo
1234 26.9.2011 11:04:02 5,6638

select * from the_table_2
----------------------------------
contract_key date_1 saldo
1234 29.9.2011 17:39:43 2,5438

how to do that ?

View 11 Replies


ADVERTISEMENT

SQL & PL/SQL :: Differences Among Records Tables And Tables Of Records

Sep 16, 2010

In Oracle database pl/sql 11.2: describe the differences between :

records,
tables, and
tables of records.

View 11 Replies View Related

SQL & PL/SQL :: How To Insert 100 Records Into Different Tables

Apr 28, 2011

i have 100 records in table1,like as we have more 15 tables without data. the issue is how can i insert above table1 data(100 records) into different 15 tables in single sql command.

View 22 Replies View Related

PL/SQL :: Get Records Count Of All Tables

Sep 26, 2012

I am trying to get the record count of all tables using dynamic query. I don't know how to put the value in placeholder. I tried the below code.

SET SERVEROUTPUT ON SIZE 1000000
DECLARE
CURSOR table_list
IS
select OBJECT_NAME from user_objects
where object_type in ('TABLE')
[code].......          

View 4 Replies View Related

SQL & PL/SQL :: Retrieving Records From Tables

Mar 27, 2010

I want to retrieve the data from ex.tables. How to get this.

table1:

Account_No, Account_sub_No
1234 1
1234 2
1234 3
2345 4
2345 5
2345 6
2345 7
2345 8
................
Account_no is the primary key

table2:

Account_sub_No, Description
1 Hello
2 Hi
3 No.1
4 great
5 people
.................
8 world
..........................
Account_sub_No is primary key.

Out put:

I want the data like Account_no who is having more than 3 Account_sub_no values.

But in my case need to join these two tables with other tables. join field is Account_no from table1. there are no other fields to join.

View 5 Replies View Related

SQL & PL/SQL :: Select Records From Table

Jun 23, 2010

I am dealing with a table containing millions of records. I have table loans_list table and he data looks similar to this..

LOAN_IDSEQUENCE_NUMCOMPLETE_DATE
1237000
1237005
1237010
5237010 6/23/2010 10:07:02 AM
5237000 6/23/2010 10:07:02 AM
12237000

I am trying to select only those loan_id from this table which contain all these 3 sequence_num = 7000,7005,7010 and containing null compelete date. I tried different way to write the query but can't think of efficient way of writing this query yet.

Since this table contain million of records, i dont prefer to call this table more than once in a query. I am just trying to avoid the longer time delay for the execution of this query..

View 7 Replies View Related

SQL & PL/SQL :: Select Records By One Column?

May 7, 2012

By select I got records (see table below) and I need to make select where result will be just one row with all values by payer_flag=Y.

There is a table:

CREATE TABLE XXX_MAPE_CC
(
CK_CUSTOMER_CODE VARCHAR2(24 BYTE),

[Code].....

And result should look like:

--------------------------------------------------------------------------------------------
ck_customer_code | invoice_media | personal_no | cnt_active | cnt_deactive | payer_flag
--------------------------------------------------------------------------------------------
6.107441.10 | electronic | 0 | 663 | 128 | Y
---------------------------------------------------------------------------------------------

View 6 Replies View Related

SQL & PL/SQL :: Select N Records In Only One Partition?

Jun 16, 2011

this is the case:

Table 1
c1 c2
1 null
2 null
3 2

[code]...

I need to select n records where c2 is null but only from one partition.In example :

In P1 (1,2,3,4)
In P2 (5,6,7)

If n = 4 --> Must be retrieve 1,2,4 because 6 is in P2.

What I tried is
(select c1 from T1 where c1 is null and rownum<=4)but retrieve 1,2,4,6 and I only need the retrieved data from P1 partition.

View 10 Replies View Related

PL/SQL :: Select Parent Records

Sep 3, 2012

Is there any SQL query which can return first value. I have 1 table, 2 columns: NR; created_from_nr;

Data:

Nr=L1 created_from_nr=''
Nr=L2 created_from_nr=L1
Nr=L3 created_from_nr=L2
Nr=L4 created_from_nr=L3

How can I get Nr=L1 if I know L4, with one query ?

View 3 Replies View Related

3 Tables In SELECT

Jul 22, 2010

When I use the below code in my perl script (it is oracle database):

$query = "select a.sub_id, b.name from subscribertable a, invitationBin b where a.subscriberid=b.subscriberid";
$sth = $dbh->prepare($sub_query) or die "SELECT-Query failed";

everything is ok... and when I try to add a third table...

$query = "select a.sub_id, b.name, c.phone from subscribertable a, invitationBin b, personalDet c where a.subscriberid=b.subscriberid and b.subIdx=c.subIdx";
$sth = $dbh->prepare($sub_query) or die "SELECT-Query failed";

this fails... it seems like it doesnt let me add 3 tables in the SELECT query through perl script. The strange is that when I test this query with Oracle SQL Developer, it works fine...!

View 1 Replies View Related

SQL & PL/SQL :: Count Of Records On Each Date?

Jan 26, 2011

PART_REF REGISTERED_BYREGISTERED_DATE
DCA544519 SVK 1/3/2011
DCA544520 SJA 1/3/2011
DCA544539 SJA 1/3/2011
DCA544572 THS 1/3/2011
DCA544608 GKA 1/3/2011
DCA544610 GKA 1/3/2011
DCA544611 THS1 1/3/2011

I just want a to get the total number of records registerd on particular date by particular user...

View 4 Replies View Related

SQL & PL/SQL :: How To Get Records Based On Max Date

May 18, 2011

I am trying to get records from a table based on date column. I should retrieve records if the date column is NULL

and if it is not null ,i shud get the records of MAX date.

How would i do this. Below is my query,by which i can get records based on either maxdate or Null date

select c.id, c.status,c.u_gr_code,
from
(
select id, status,u_gr_code,date_col,
max(record_valid_from) over (partition by entity_user_gr_id, status_id) max_date
[code].........

View 10 Replies View Related

Querying Records From Temporary Tables

Feb 2, 2011

I have a temporary table (with on commit preserve rows property) which is populated thru insert into command from a procedure. After which, i need to query the records from the populated temp table.

However, my query returns nothing. My procedure works fine cause i tried executing it to populate a regular table and it is ok. However, it shows no output in the temp table cause probably it is creating another session. How do i select the rows from the temp table after populating it from a procedure.

View 3 Replies View Related

How To Display Unmatched Records In Two Tables

Feb 28, 2008

I want to display all records from table 1 (even the null values) that do not match records in Table 2. Below I am creating both tables and I am posting the result query I need.

------------------------------------
CREATE TABLE temp_table1
(
name VARCHAR2(12 BYTE),
last_name VARCHAR2(12 BYTE),
STATE VARCHAR2(2 BYTE),
BIRTH_DATE DATE
);

CREATE TABLE temp_table2
(
name VARCHAR2(12 BYTE),
last_name VARCHAR2(12 BYTE),
STATE VARCHAR2(2 BYTE),
BIRTH_DATE DATE
);

[code].....

The result query need to have 5 rows as shown below

NAME LAST_NAME STATE BIRTH_DATE
------------ ------------ ----- ---------------------
john smith MA 12/1/1979
null null AZ null
null null CT null
null null MA null
null null CT null

View 5 Replies View Related

SQL & PL/SQL :: List Records Being Deleted From All The Tables

Jan 10, 2011

I am executing a script that is deleting some parent records and the corresponding child records as I have used the "on delete cascade" with the Foreign key Constraint.

My question is that can I list the records that are being delete from all the tables i.e. both parent and child tables. Is some thing like spooling can work in this or do I have some other option with which I can see(select) all the deleted records.

View 12 Replies View Related

Delete Records From Multiple Tables

Jun 27, 2011

I have a service that executes a pl/sql function (legacy app) to delete records from multiple tables. This function works fine in development, and has worked fine in production until about a week ago. I'm not a DB guy but the DB guys are trying to say this is an application issue. That may be, be the "insuff privileges" really leads me to believe otherwise.

What is causing this type of Oracle error? Permissions between dev and prod are the same, yet it works in dev but not prod.

ORA-29876: failed in the execution of the ODCIINDEXDELETE routine
ORA-20000: Oracle Text error:
DRG-50857: oracle error in textindexmethods.ODCIIndexDelete
ORA-20000: Oracle Text error:
DRG-10602: failed to queue DML change to column ABSTRACT for primary key AAAfBoAAEAABa62AAA
DRG-50857: oracle error in drexrdml
ORA-01031: insufficient privileges
[code]....

View 2 Replies View Related

SQL & PL/SQL :: Select Max Date And Pk?

Sep 6, 2013

here is my query

select
max(PERIOD_DUE_DATE) , form_submission_id
from form_submission
group by
form_submission_id

but this returns all the records, I need only the max date along with its form_submission_id.In reality Its a complex query but to explain my problem I putting this simple query, how to select max(column) and column2 from table.

View 4 Replies View Related

SQL & PL/SQL :: Select Only Last Date?

Jun 25, 2011

How do I select only last date for each contragentid? So for contragentid = 111270 it should be only '14.05.2010'.

select dd.contragentid,
decode(dd.ratingvalue,'PK1',1,'PK2',2,'PK3',2,'PSR',2,'UN4',2,'VVL',2,'BK',4,3) as ratingvalue from
(select 36 as contragentid, 'UN1' as ratingvalue, '25.02.2010' as ratingstartdate from dual
union all
select 111270 as contragentid, 'PK1' as ratingvalue, '26.11.2009' as ratingstartdate from dual
union all
select 111270 as contragentid, 'PK3' as ratingvalue, '14.05.2010' as ratingstartdate from dual
union all
select 111270 as contragentid, 'BK' as ratingvalue, '14.06.2011' as ratingstartdate from dual ) dd
where dd.ratingstartdate <= to_date('31.05.2010', 'DD.MM.YYYY')

Also I need to select all rows from second test case for those contragentid which absent in first case, it should be one statement for both cases.

select * from
(select 5 as contragentid, 2 as ratingvalue from dual
union all
select 111270 as contragentid, 1 as ratingvalue from dual ) hh

View 8 Replies View Related

Select Query Not Fetching Records In 11g?

May 10, 2013

I have a Select query which is not fetching records in 11g (11.2.0.2.0) but working fine in 10g (10.2.0.4.0). The query is as below.

--CREATE TABLE t1 (col1 NUMBER, col2 VARCHAR2 (15 CHAR), flag varchar2(1))

--insert into t1(col1, col2, flag) values(1, 'a', 'Y');
--insert into t1(col1, col2, flag) values(2, 'b', 'N');

SELECT *
FROM t1 x
WHERE col1 = 1 AND col2 = 'a' -------------- condition1
AND 0 = -------------- condition2
NVL (
(SELECT COUNT (1)
FROM t1 y
WHERE y.flag = 'N'
AND x.col1 = y.col1
AND x.col2 = y.col2),0)--=0

When remove NVL function or change the condition by having AND NVL(SELECT) =0 the query working fine.

View 9 Replies View Related

Select Records With Same Values Of Field?

Oct 9, 2007

there are some data in the table que_history (seqnbr is the key), e.g.

SEQNBR DN SL_TIME
20070927003668 (024)2272 AD182040 2007-9-27 15:15:00
20070928001343 (024)2272 AD182040 2007-9-28 9:55:14
20070928001624 (024)2272 AD182040 2007-9-28 10:30:06
20070928000910 (024)25672 AD000002 2007-9-28 9:06:59
20070928001288 (024)25672 AD000002 2007-9-28 9:49:13
20070923003834 (024)2585 AD210076 2007-9-23 17:15:13
20070923003890 (024)2585 AD210076 2007-9-23 17:23:54
20071001001593 (024)2589 AD000018 2007-10-1 11:54:39
20071003002814 (024)2589 AD000018 2007-10-3 16:53:52
20070923003320 (024)8831 AD000110 2007-9-23 15:24:39

I wanted to use this SQL to get the records ( dn is the same and the sl_time's interval is 600minutes) .

select A.* from que_history A,que_history B
where A.dn=B.dn and A.seqnbr<>B.seqnbr
and (A.sl_time-B.sl_time)*24*60 between -600 and 600
order by A.dn;

but the result is not the right.

View 3 Replies View Related

SQL & PL/SQL :: SELECT Records In The Order They Were Inserted

Apr 12, 2011

I would like to write a select statement on a table and I want the records to be retrieved in the order they were inserted.

View 17 Replies View Related

Forms :: How To Select Multiple Records

Feb 23, 2012

I'd want to select multiple records in my multi-record block. I'd also want to do that with checkboxes. When the user clicks on a particular checkbox, that should be selected and whatever record the user wants to check it should be added to selected records.

View 39 Replies View Related

How To Select Rows From Two Tables

Aug 30, 2007

Consider the following tables

MANAGERID
101
102
103
104

MANAGERID EMPID
101 ----------------24
101-----------------25
101 ----------------26
104 --------------- 27

write sql query to get the following output without using minus,union,intersect.

MANAGERID EMPID
101 ---------------------------------- 24
101------------------------------------25
101 -----------------------------------26
102 -----------------------------------N/A
103 -----------------------------------N/A
104 -----------------------------------27

View 3 Replies View Related

Select Query From Two Tables?

Jun 7, 2011

I have two tables a and b column names are id and date. Data type of date in a and b are different

table (a)

date id
10-DEC-01 2:08:39 PM 1
10-DEC-01 2:08:39 PM 2
10-JAN-02 10:10:22 PM 3
10-JAN-02 10:10:22 PM 4
10-JAN-02 10:10:22 PM 5

table (b)
date id
10-DEC-01 1
10-DEC-01 2

I need table b like this one

table (b)

date id
10-DEC-01 1
10-DEC-01 2
10-JAN-02 3
10-JAN-02 4
10-JAN-02 5

View 1 Replies View Related

SQL & PL/SQL :: Select Count Using 2 Tables?

Mar 28, 2011

I'm having trouble with some SQL code regarding count and an outer join.

Here is my code.

SELECT o.salespersonid, Count(*) from
salesperson s, Ord o
Where s.salespersonid(+) = o.salespersonid
Group By o.salespersonid;

Where salesperson is a salesperson table and ord is a table containing orders.

The orders table contains a FK to salespersonid in the salesperson table.

I want it to return all salespersons along with the amount of orders they are on. It works but does not show the ones that do not appear on any orders hence the outer join.

View 13 Replies View Related

SQL & PL/SQL :: Select Data From All Tables At Once

Sep 12, 2011

Is there any way i can select * from all the tables owned by particular schema at once.

View 22 Replies View Related

SQL & PL/SQL :: Select From Multiple Tables?

Mar 29, 2011

I have two tables containing dates:

A
From____________To________
01.01.2009 || 01.01.2010
01.01.2013 || 01.10.2014

B
From____________To________
01.01.2007 || 01.01.2008
01.01.2011 || 01.10.2012
01.01.2009 || 01.01.2010
01.01.2015 || 01.01.2016

I need to get list of all entries from Table A and entries from B where dates are before min begin date from A or somewhere between any entry from A.

In this Example result:
From____________To________
01.01.2007 || 01.01.2008
01.01.2009 || 01.01.2010
01.01.2011 || 01.10.2012
01.01.2013 || 01.10.2014

View 1 Replies View Related

Find Records That Have Most Current Date?

Apr 13, 2004

I have two tables

table_1
--Emp_id--|--Sup_id--|Sup_name|--Date--|
-------------------------------------------------
--00001--|--00005 --|---ABCD--|01-MARCH-2004
--00002--|--00006 --|---BCDE--|02-MARCH-2004
--00003--|--00007 --|---CDEF--|03-MARCH-2004
--00001--|--00008 --|---DEFG--|04-APRIL-2004
--00003--|--00009 --|---EFGH--|05-APRIL-2004

table_2
--Emp_id--|Emp_name|
--------------------------------
--00001--|--QWER--|
--00002--|--ASDF--|
--00003--|--ZXCV--|
--00004--|--POIU--|

table_1 contain records on employee and the supervisor they are under at a certain date.

As some employee(00001 & 00003) have a different supervisor from different date, I'll like to extract from table_1 the record of each employee in the table that only contain the supervisor info on the most recent date.And from table_2, i'll like to extract the employee's name. These records extracted from both the tables would the be put into a new table,table_3

Example: For employee 00001, only extract record that have the most recent date which is 04-APRIL-2004 and not on 01-MARCH-2004

table_3
Emp_id|Emp_name|Sup_id|Sup_name|Date|
------------------------------------------------
00001 |--QWER--|00008 |--DEFG---|04-APRIL-2004
00002 |--ASDF-- |00006 |--BCDE---|02-MARCH-2004
00003 |--ZXCV-- |00009 |--EFGH---|05-APRIL-2004

How to write an SQL statement to perform this?

View 6 Replies View Related

SQL & PL/SQL :: MAX DATE - Getting Records Out Of Source Table

Sep 28, 2011

Below is my requirement,

Source Table: SRC

COL1 DATE_CREATED CREATED_BY
1 27-SEP-2011 GURU
1 28-SEP-2011 SANKAR

Target Table:TGT

COl1 DATE_CREATED CREATED_BY
1 28-SEP-2011 SANKAR

I need to take the MAX of date_created record and store it in target.

I tried,

select max(date_created), col1, created_by from src
group by col1, created_by,date_created

Which is giving me 2 records which i don't want. How to get only one record out of that source table?

View 2 Replies View Related

SQL & PL/SQL :: Counting Records Within A Date Range?

Nov 1, 2011

I am trying to write part of an SQL where it gives me a count of bookings in any 6 month period made from the first booking.Example of records

enquirynumberenquiryaddresssubjectcodebookingdate
613651 Burberry AvenueBCHR20/10/2008 07:00:00
613801 Burberry AvenueBCHR20/11/2008 07:00:00693021 Barberry AvenueBCHR07/09/2009 07:00:00

I am so far getting 3 as a count result based on SQL below. I want the count to return 2 (because its inside the 6 month range):

SELECT
ce1.enquirynumber,
ce1.enquiryaddress,
es1.subjectcode,
b1.bookingdate,
(SELECT count(b2.bookingdate)
[code]....

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved