Home > Database > Mysql Tutorial > body text

mysql设置临时变量一次性查出多层依赖的sql语句

WBOY
Release: 2016-06-07 15:35:02
Original
1316 people have browsed it

在实际工作中,我们常常会遇到这种情况,想要查的sql和已知的数据中间要通过许多的中间sql依赖查询。开始的方法是先执行已知数据的sql,查出想要的中间数据,以此类推,再执行中间sql,直到查出最终要的数据。用navcat工具的话,每次都要右键--执行,挺麻烦

        在实际工作中,我们常常会遇到这种情况,想要查的sql和已知的数据中间要通过许多的中间sql依赖查询。开始的方法是先执行已知数据的sql,查出想要的中间数据,以此类推,再执行中间sql,直到查出最终要的数据。用navcat工具的话,每次都要右键-->执行,挺麻烦的。

        现在有一种方法,一次执行这些sql,方式如下:

select @pid:=id from buy_order where id = 52;

select buy_order_id from buy_order_product where buy_order_id = @pid;
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!