create table customers (
cust_id number not null primary key,
cust_name varchar(100)
)
Table created.
insert into customers (
cust_id,
cust_name
) values (
1234,
'John Doe')
1 row(s) inserted.
insert into customers (
cust_id,
cust_name
) values (
1235,
'Ram')
1 row(s) inserted.
insert into customers (
cust_id,
cust_name
) values (
1236,
'Rahim')
1 row(s) inserted.
create table customer_review (
review_id varchar2(15) not null primary key,
cust_id number,
remarks varchar2(50) not null,
contact_date date,
contact_time TIMESTAMP
)
Table created.
insert into customer_review (
review_id,
cust_id,
remarks,
contact_date,
contact_time
) values (
'CUST123',
1234,
'This is awsome product',
TO_DATE('2019-10-26','YYYY-MM-DD'),
TO_TIMESTAMP('26-OCT-2019 17:00:00:00','DD-MON-YYYY HH24:MI:SS:FF')
)
1 row(s) inserted.
insert into customer_review (
review_id,
cust_id,
remarks,
contact_date,
contact_time
) values (
'CUST124',
1234,
'This is not good product I chnaged mind now',
TO_DATE('2019-10-27','YYYY-MM-DD'),
TO_TIMESTAMP('27-OCT-2019 17:00:00:00','DD-MON-YYYY HH24:MI:SS:FF')
)
1 row(s) inserted.
insert into customer_review (
review_id,
cust_id,
remarks,
contact_date,
contact_time
) values (
'CUST125',
1234,
'After update now it is working fine',
TO_DATE('2019-10-27','YYYY-MM-DD'),
TO_TIMESTAMP('27-OCT-2019 17:00:00:00','DD-MON-YYYY HH24:MI:SS:FF')
)
1 row(s) updated.
insert into customer_review (
review_id,
cust_id,
remarks,
contact_date,
contact_time
) values (
'CUST125',
1235,
'I am new user',
TO_DATE('2019-10-27','YYYY-MM-DD'),
TO_TIMESTAMP('27-OCT-2019 17:00:00:00','DD-MON-YYYY HH24:MI:SS:FF')
)
ORA-00001: unique constraint (SQL_FFMZVSKKUAGCTMXBASBAVULAG.SYS_C0020027882) violated ORA-06512: at "SYS.DBMS_SQL", line 1721More Details: https://docs.oracle.com/error-help/db/ora-00001
insert into customer_review (
review_id,
cust_id,
remarks,
contact_date,
contact_time
) values (
'NEW123',
1235,
'I am new user',
TO_DATE('2019-10-27','YYYY-MM-DD'),
TO_TIMESTAMP('27-OCT-2019 17:00:00:00','DD-MON-YYYY HH24:MI:SS:FF')
)
1 row(s) inserted.
SELECT a.cust_id,b.remarks,b.contact_date,b.contact_time FROM customers a,(select * from customer_review
where (cust_id,contact_time,contact_date) in (select cust_id, max(contact_time),max(contact_date) from customer_review group by cust_id)
) b WHERE a.cust_id=b.cust_id
CUST_ID | REMARKS | CONTACT_DATE | CONTACT_TIME | 1235 | I am new user | 27-OCT-19 | 27-OCT-19 05.00.00.000000 PM | 1234 | This is not good product I chnaged mind now | 27-OCT-19 | 27-OCT-19 05.00.00.000000 PM | 1234 | After update now it is working fine | 27-OCT-19 | 27-OCT-19 05.00.00.000000 PM |
---|
select * from customers
CUST_ID | CUST_NAME | 1234 | John Doe | 1235 | Ram | 1236 | Rahim |
---|
select * from customer_review
REVIEW_ID | CUST_ID | REMARKS | CONTACT_DATE | CONTACT_TIME | NEW123 | 1235 | I am new user | 27-OCT-19 | 27-OCT-19 05.00.00.000000 PM | CUST123 | 1234 | This is awsome product | 26-OCT-19 | 26-OCT-19 05.00.00.000000 PM | CUST124 | 1234 | This is not good product I chnaged mind now | 27-OCT-19 | 27-OCT-19 05.00.00.000000 PM | CUST125 | 1234 | After update now it is working fine | 27-OCT-19 | 27-OCT-19 05.00.00.000000 PM |
---|