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 (

> 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

Written By
October 10, 2020 07:44AM
Re: Using UNION for multi query
October 10, 2020 10:04AM
October 10, 2020 10:52PM
October 11, 2020 09:49AM

Sorry, you can't reply to this topic. It has been closed.

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.