0

I have an query:

update customers_training_malaysia
set
     period_id = (select b.id 
                  from customers_training_malaysia a,training_schedules_malaysia b
                  where a.sch_code=b.sch_code order by a,id)
where
     sch_code = (select b.sch_code 
                 from customers_training_malaysia a,training_schedules_malaysia b
                 where a.sch_code = b.sch_code order by a.id)

I tried to run following query update, but I get only the error

more than one row returned by a subquery used as an expression

What shall I do to correct the sql query?

1
  • Maybe try adding a limit 1 to your subquery? Commented Feb 17, 2011 at 8:12

2 Answers 2

1

You must get all your subqueries in

set [field_name] = ([subquery])

and check that this queries returning only one record in results. That is reason for the error - multiple results in your subqueries

Try this:

update customers_training_malaysia
set
     period_id = b.id
where
     sch_code = (select b.sch_code 
                 from customers_training_malaysia a,training_schedules_malaysia b
                 where a.sch_code = b.sch_code order by a.id)
Sign up to request clarification or add additional context in comments.

Comments

0
order by a,id)

Is this a typo?

**","** used it should be a.id

And Add from the other answer Below it might be returning more than one result, because of order by condition i assumed that!

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.