Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Oracle SQL Update Statement Query Syntax

Posted on 2016-08-24
3
Medium Priority
?
116 Views
Last Modified: 2016-08-25
Hello Experts,

I've created the following two temporary tables:

TABLE JS_ARRESTS (with the following fields)

CASE_ID
FILING_DATE
CASE_NUMBER
OFFENSE_DATE
ARREST_DATE
CHRG_NBR
DGOF_CD
CHARGE
CHRG_DESC
DFNDT_LAST_NAME
DFNDT_FIRST_NAME
DFNDT_MIDDLE_NAME
DFNDT_DOB
DFNDT_SSN
ARRAIGNMENT_DATE

TABLE JS_ARRAIGNMENT_EVENTS (with the following fields)

CASE_ID
CASE_NUMBER
COURT_DATE
EVENT_ID
COURTROOM
EVENT_CODE
EVENT_DESC
RESULT_DATE
RESULT_CODE
RESULT_DESC

I want to update the ARRAIGNMENT_DATE field in the JS_ARRESTS table
with the COURT_DATE values in the JS_ARRAIGNMENT_EVENTS table
whenever the JS_ARRESTS.CASE_ID = JS_ARRAIGNMENT_EVENTS.CASE_ID
and the JS_ARRAIGNMENT_EVENTS.COURT_DATE > JS_ARRESTS.ARREST_DATE.

I found the following update statement online, but when I use it in SQL Developer, I get the error message below.

update js_arrests
set arraignment_date = (select court_date
from js_arraignment_events
where js_arrests.case_id = js_arraignment_events.case_id
and js_arraignment_events.court_date > js_arrests.arrest_date)
where exists (select court_date
from js_arraignment_events
where js_arrests.case_id = js_arraignment_events.case_id
and js_arraignment_events.court_date > js_arrests.arrest_date);

Error report:
SQL Error: ORA-01427: single-row subquery returns more than one row
01427. 00000 -  "single-row subquery returns more than one row"
*Cause:    
*Action:
0
Comment
Question by:jsmith08
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Accepted Solution

by:
Abhimanyu Suri earned 1000 total points
ID: 41769638
Because below mentioned SQL must be returning more than 1 record

select court_date
from js_arraignment_events
where js_arrests.case_id = js_arraignment_events.case_id
and js_arraignment_events.court_date > js_arrests.arrest_date

Assuming, you want the latest court_date as per table js_arraignment_events, please use something like

select court_date from (select court_date
from js_arraignment_events
where js_arrests.case_id = js_arraignment_events.case_id
and js_arraignment_events.court_date > js_arrests.arrest_date
order by court_date_desc) CRT_DT where rownum < 2
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 41769809
Please review this article I wrote to handle "updates with join":
https://www.experts-exchange.com/articles/1517/UPDATES-with-JOIN-for-everybody.html
0
 

Author Closing Comment

by:jsmith08
ID: 41770046
Thank you very much for your help! I've accomplished what I needed to do.
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This video shows how to recover a database from a user managed backup

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question