Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Experts,


I have a question regarding MySQL.
Suppose My query is like below
SQL
select col1 from table1 where col2='value'

now what ever I get in col1 should be a value to second query where clause like below
SQL
select col1,col2,col3 from table2 where col6='col1 value from above query'

These things should be in a stored procedure.

Can anyone help me with this? I haven't tried any because didn't know how to do. I didn't have any basic idea about these as well. any tutorials are also much appreciated.
Couldn't find MySQL in Tags so I select SQL
Posted
Updated 20-Feb-15 4:53am
v3
Comments
PIEBALDconsult 20-Feb-15 10:59am    
Subqueries tend to perform poorly; I'd use a JOIN instead.
sudevsu 20-Feb-15 11:58am    
Correct I agree Sub queries are not good at performance. What if I have more than 6 queries that I want to save result in variable and pass that as clause in next query in my Stored procedure? can that be possible? If yes Can you show me how with the above two queries?

Learn to create mysql stored procedure[^]
As for the sql query, try this:
SQL
Select col1, col2, col3 from table2 where col6 in 
(
   Select col1 from table1 where col2='value'
)
 
Share this answer
 
Comments
sudevsu 20-Feb-15 11:56am    
But what if I have something 6 or more like these two queries. I want to use something like result should be in some variable. Can this be possible?
And a MySQL tutorial site http://www.mysqltutorial.org/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900