SELECT .. INTO returns more than one rows - Mysql

删除回忆录丶 提交于 2019-12-02 17:02:24

问题


i have a basic stored procedure

DECLARE user_o VARCHAR(50);

SELECT user_name INTO user_o FROM users WHERE topic_id = 54 AND entry_time BETWEEN 
2017-09-17 AND date_add( CURRENT_DATE, INTERVAL 1 DAY) ORDER BY entry_time ASC 
LIMIT 10;

this throws me error #1172 sql returns more than one rows. no idea why?

my goal is to have this result set

user_name |  user_o
  mike       mike
  liz        liz
  helen      helen
  her        her

回答1:


Its because you are inserting the result 'INTO' a variable and because the result is more than a single value, hence the error.

You have a limit of 10, try changing to 1, that will fix it, if you want multiple values returned then you need to manage these in a recordset.



来源:https://stackoverflow.com/questions/46342943/select-into-returns-more-than-one-rows-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!