I am trying to create a stored procedure but giving me an er开发者_C百科ror: Subquery returns more than 1 row for the below query . This could be done using cursors but are there any other ways to directly run this query in stored procedures without using cursors since there are multiple queries of this type which i need to add in stored procedure for multiple tables.
Query:-
UPDATE ipcc_patent_ipc_class
SET assignee_type = (
SELECT IF(ipcc_patent_master.assignee_type='$ipcc_config_param[0]',$ipcc_config_value[0],IF(ipcc_patent_master.assignee_type='$ipcc_config_param[1]',$ipcc_config_value[1],null))
FROM ipcc_patent_master
WHERE ipcc_patent_ipc_class.patent_id = patent_uid);
But this Query Works for multiple field:-
UPDATE ipcc_patent_ipc_class
SET geographies_id=(
SELECT ipcc_geographies.geographies_uid
FROM ipcc_patent_master,ipcc_geographies
WHERE ipcc_patent_master.geographies = ipcc_geographies.geographies
AND ipcc_patent_ipc_class.patent_id = ipcc_patent_master.patent_uid
),
jurisdictions_id =(
SELECT ipcc_jurisdictions.jurisdisctions_uid
FROM ipcc_patent_master,ipcc_jurisdictions
WHERE ipcc_patent_master.jurisdictions = ipcc_jurisdictions.jurisdictions
AND ipcc_patent_ipc_class.patent_id = ipcc_patent_master.patent_uid
),
country_code_id =(
SELECT ipcc_country_code.country_code_uid
FROM ipcc_patent_master,ipcc_country_code
WHERE ipcc_patent_master.country_code= ipcc_country_code.country_code
AND ipcc_patent_ipc_class.patent_id = ipcc_patent_master.patent_uid
);
Add Limit clause in your sub query.
Add more terms to your subquery's WHERE
clause to bring it down to one record, or add a LIMIT
clause to the same.
I don't think you need a subquery here at all. You can reference multiple tables directly in the UPDATE query:
http://dev.mysql.com/doc/refman/5.0/en/update.html
Problem solved... for the subquery (SELECT Statement), alias was missing for patent_uid which lead to this error. After entering the table name as alias,it started working properly inside stored procedure..
Thanks Guys for your kind help...
精彩评论