MySQL Forums
Forum List  »  Stored Procedures

Re: Using UNION for multi query
Posted by: Peter Brawley
Date: October 10, 2020 10:04AM

> How do I use UNION for multi query

"Multi-query" implies multiple resultsets. Union returns one resultset. You want one resultset, or two?

> call new_procedure_total_emp_dept(@dept_id ,@result);

The posted code doesn't use @dept_id.

> ... (count(staff_title)/@result)*100 ...

@result references a user variable by that name, not a parameter passed to the sproc, which would be something like this ...

create procedure staffinfo( pdeptid unsigned int, presult unsigned int )
...
select dn,staff_title, count(staff_title) as StaffN, (count(staff_title)/presult)*100 as Pct
from (
...

> ...group by de.emp_no...

Each of the subqueries issues Group By, neither aggregates. The result therefore arbitrarily removes duplicates without specifying which duplicates to remove. That's unsound. What's the intended effect of Group By in those subqueries?

Options: ReplyQuote


Subject
Views
Written By
Posted
165
October 10, 2020 07:44AM
Re: Using UNION for multi query
63
October 10, 2020 10:04AM
63
October 10, 2020 10:52PM
55
October 11, 2020 09:49AM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.