Mysql Stored Procedure - get rows from multiple database tables - mysql

I am trying to get rows from multiple database tables in one of the database stored procedure in mysql.
Is this possible?
Please can you give me example about this.
CREATE DEFINER=`root`#`localhost` PROCEDURE `user_procedure`(IN uid_user int)
BEGIN
select ucgm_id from `conne`.conn_group_membership where uid=uid_user;
END

Cursors can take data from multiple tables, and you can use them in procedures.

Related

Storing MySQL Stored Procedure Result Into Temporary Table

In SQL Server, I used to create a table variable to store results from a certain stored procedures. This is how I usually do with table variable.
DECLARE #My_Table_Variable TABLE(col_1 FLOAT, col_2 FLOAT)
INSERT INTO #My_Table_Variable(col_1, col_2) EXEC [My_Procedure]'param_1','param_2'
Now, while using MySQL, I recognized that table variable doesn't exist. I've seen some questions related to this, for instance, this one says it's not possible to SELECT something FROM a procedure.
How about temporary table? Can we CALL a procedure, and then put the result into a temporary table? With the syntax something like this:
CALL my_procedure('my_first_parameter','my_second_parameter') INTO my_temporary_table;
which allows me to query from my_temporary_table. Is this possible to be performed?

Call stored procedure from stored procedure in MySQL

i'm new to MySQL.
I need to call stored procedure from a stored procedure and use the first stored procedure as a table.
How to do this without use temporary table?
How to do this without use temporary table?
create a fact table then
Not sure why there is a requirement saying: can't use temporary table as you are using store procedure. but that must be unreasonable.
if the RDBS takes care of that for you , the underlying mechanism is still store the 1st result set somewhere in the memory as middle step result. temporary table for you.
so just: create a temporary table, call the store procedure, insert data into that . why not

MySQL stored procedures out variable as array

I have MySQL procedure where I want to get a result of query:
SELECT id FROM mbus_clients WHERE second_name like surnamePart AS
So it should be an array. The decision I've found in the internet is to use temporary table.
But how can I return a table and read with PHP? Is it ok?
Simply call the procedure:
CALL procedurename();
If the procedure performs a SELECT, the result set of the procedure call will be the same as if you'd performed the query itself. You can then fetch the rows using PHP the same way as if you'd performed a SELECT.

get records from procedure having multiple select statements in mysql

I have created a procedure in mysql having multiple select statements in it.
Here is my code :
DELIMITER $$
USE `databasename`$$
DROP PROCEDURE IF EXISTS `wholeProjectDetails`$$
CREATE DEFINER=`databasename`#`localhost` PROCEDURE `wholeProjectDetails`(IN givenpid INT)
BEGIN
select * from projects where projectid=givenpid;
select * from projects where projectid<>givenpid;
END$$
DELIMITER ;
When i called this procedure using statement :
call wholeProjectDetails(2);
it is displaying only first statement's results, i want that it will display both statement's records.
Please let me know what i am doing wrong?
Thanks
When you call this procedure, MySQL creates two result-sets. Now, you need to get these two result-sets using your MySQL client. Read information about client you use, does it support this feature? For example, in .NET you can use IDataReader.NextResult Method, in mysqli - mysqli::next_result function, and so on.
If you want just to view these result-sets, you can install one of MySQL GUI tools, there are free ones.

MySQL : How to link a stored procedure to a table

How can I link a stored procedure to a temporary table?
I had a database created named Multi. All the attributes of table registration are copied into the stored procedure. In this you cannot insert from stored procedure. This is just creating a stored procedure and giving it something to hold.
This is the example of it.