0

Hi my problem is I want to update a field in 1 table using another field from several tables dependant upon where the item originates my only problem is the table which im trying to update has several of the same values in so am getting 'single row sub-query returns more than 1 row'. I dont mind all of the updated fields with the same value being the same. Heres my SQL:

update URL_SET_TAB u
Set U.ITEM_NAME = (select a.PROGRAMME_NAME
                   from (SELECT (nvl(nvl(b.prog_name,c.movie_name), A.URL_1)) as programme_name, a.ID, a.URL_1
                         FROM URL_SET_TAB a, prog_name_lookup b, movie_name_lookup c 
                         where a.url_1 = b.url_1(+) and a.url_1 = C.MOVIE_URL(+)
                         ) a
                   where u.ID = a.ID and U.URL_1 = a.URL_1
                   )
4
  • As you have a distinct in the subquery this means that your assertion "all of the updated fields with the same value being the same" is not correct, there are different values from the subquery
    – mmmmmm
    Sep 20, 2013 at 11:15
  • sorry I use oracle and sorry that distinct was added when trying to sort it ill remove it now
    – Charlie
    Sep 20, 2013 at 11:17
  • error : single row sub-query return more thaan 1 row' can occur due to multiple values coming from subquery (while selecting programme_name). It may not happen due to multiple rows exist in url_set_tab table. As you told you are getting multiple rows for on ID and URL_1 values but those values are same then to overcome the error regarding multiple rows you can add distinct word while select a.programme_name. Sep 20, 2013 at 11:37
  • I had that already as discussed in the previous comments but still gave the same error
    – Charlie
    Sep 23, 2013 at 6:14

1 Answer 1

0

You need to identify a key column which when matched for URL_SET_TAB and inline view a so that the subquery returns only a single record. This is a limitaion of an UPDATE clause.

Thanks, Aditya

1
  • what are my possibilitys if I have no unique key which matches my other queried tables?
    – Charlie
    Sep 23, 2013 at 6:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.