简体   繁体   English

mysql中的select语句存储过程

[英]select statement stored procedure in mysql

I have three tables in database:我在数据库中有三个表:

user_tbl: userID | name | email | password
task_tbl: taskID | description | Date
usertask_tbl: userID | taskID

Now i want to display all the tasks related to one user, it should go and get check the taskid of that user and show all the description and date for that user.现在我想显示与一个用户相关的所有任务,它应该去检查该用户的 taskid 并显示该用户的所有描述和日期。 But instead its showing one description and date.但它显示了一个描述和日期。

Here is my stored procedure:这是我的存储过程:

CREATE DEFINER=`root`@`localhost` PROCEDURE `alltask`(IN `useremail` INT(11))
BEGIN
SELECT @userID := userID FROM user_tbl WHERE email=useremail;
SELECT @TaskID :=taskID from usertask_tbl WHERE userID = @userID;
SELECT description, Date from task_tbl WHERE taskID = @TaskID;
END

I'm new to this.我是新手。 If this is not the right way to do it please help me.如果这不是正确的方法,请帮助我。

You are only selecting one task when you do:当您执行以下操作时,您只会选择一项任务:

SELECT @TaskID :=taskID from usertask_tbl WHERE userID = @userID;

Therefore, instead of:因此,而不是:

SELECT @TaskID :=taskID from usertask_tbl WHERE userID = @userID;
SELECT description, Date from task_tbl WHERE taskID = @TaskID;

Try:尝试:

SELECT description, Date from task_tbl AS t1
INNER JOIN usertask_tbl AS t2 ON t1.taskID = t2.taskID
WHERE userID = @userID;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM