1

I have two stored procedure which returns something like this:

call proc1('Jack');
+------+------------+
| 3232 |   Admin    |
+------+------------+
| 3254 | SuperUser  |
+------+------------+
| 3264 | Admin      |
+------+------------+

call proc2('Martin');
+------+--------+
| 6345 | User   |
+------+--------+
| 6309 | Stuff  |
+------+--------+

How can I use combine the result of those two procedure and use the final result?

Martin AJ
  • 6,261
  • 8
  • 53
  • 111
  • Do you want to do this in SQL or PHP – RiggsFolly Aug 19 '17 at 17:18
  • @RiggsFolly In SQL, but if it is not possible, then in PHP. – Martin AJ Aug 19 '17 at 17:19
  • @RiggsFolly `#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'union all call proc2('Martin')' at line 1` – Martin AJ Aug 19 '17 at 17:22
  • @RiggsFolly Please reopen my question, that question is about SQL SERVER. – Martin AJ Aug 19 '17 at 17:25
  • Yea, just noticed that, my mistake – RiggsFolly Aug 19 '17 at 17:27
  • https://stackoverflow.com/questions/19580499/mysql-make-a-stored-procedure-from-multiple-stored-procedures – RiggsFolly Aug 19 '17 at 17:28
  • @RiggsFolly Thx for the link you provided. Also I have a totally different question. I have a `LIMIT` clause in my query, I need to set something to it which don't limit the result at all. Something like `LIMIT -1`, but it throws syntax error. *(Noted that I cannot remove that `LIMIt` clause)* – Martin AJ Aug 19 '17 at 17:37

2 Answers2

1

I would suggest you, You can create the new procedure and invoke both procedure proc1 and proc2 inside the new procedure and also perform union operation inside new procedure by creating a temparory table. for example:

create Procedure get_union_proc(your_parameter ...)
BEGIN
Insert INTO #Temp_table1 exec proc1;
Insert INTO  #Temp_rable2 exec proc2;
select * from Temp_table1
union
select * from Temp_table2
END get_union_proc

I hope it would be helpful.

Vinod Kumawat
  • 741
  • 5
  • 8
-2

You Need to create a temporary table and fetch results from the temporary table.

INSERT INTO #TempTable
EXEC StoredProc0;
INSERT INTO #TempTable
EXEC Storedproc1;

Select * from TempTable;