在存储过程中迭代选择查询

时间:2011-08-24 12:02:08

标签: mysql sql stored-procedures

我处于存储过程必须执行的情况

查询1:

select columnName from tablename where=(some condition)

并使用此查询的输出我不知道在哪种数据类型中存储它,我想执行另一个必须在同一存储过程中执行的查询,该查询依赖于查询1的输出。 / p>

QUERY2:

select * from tablename where column2=(result of query1)

请告诉我如何实现这一点,基本上我正在寻找像Java中的ResultSet或Mysql中的C#中的DataReader。

1 个答案:

答案 0 :(得分:1)

select t2.col1, t2.col2, t2.col3 from tablename t2 
join tablename t1 on t1.columnname = t2.column2
where (some condition) 

选择那样的列,然后您可以在表格中查找适当的变量来存储字段