prkash
prkash

Reputation: 449

Mysql stored procedure using 2 tables with one similar column

Well I have 2 tables in a single schema and both have a column named agentlogin

For example table 1 has columns [agentlogin], [password]

Table 2 has columns [agentlogin], [agentName],[location]

I need to fetch all the datas from table 2 based on the [agentlogin] from table 1. Is there a way to do it using MySql stored procedure? Please let me know. Thanks in advance.

Upvotes: 0

Views: 99

Answers (2)

prkash
prkash

Reputation: 449

I tried this using MySql stored procedure as it is mandatory for me and it works great.

CREATE DEFINER=`root`@`localhost` PROCEDURE `agentRegister`()
BEGIN
SELECT authentication.agentlogin, agentdetails.TM, agentdetails.shift, agentdetails.skill2 FROM agentdetails
INNER JOIN authentication ON agentdetails.agentlogin = authentication.agentlogin  WHERE agentdetails.location = 'PNQ10-Pune' ORDER BY agentlogin;
END

Upvotes: 0

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521093

You don't even need a stored proc to do this; a regular query should be just fine:

SELECT t2.*
FROM table2 t2
INNER JOIN table1 t1
    ON t1.agentlogin = t2.agentlogin;

Upvotes: 1

Related Questions