Reputation: 1413
how can I use mysql variable for my sql? sometimes I have to write some very long sql joining several tables to get results. I want to set some vars to shorter my main sql, how to set vars in mysql?
// this is the normal sql
select
a.name,a.money,b.mail
from
(select name, sum(money) from moneys group by name) as a
left join (select name ,email from persons) as b on a.name = b.name
// I want to using variable to make my sql shorter and easy to understand, how to write?
select
a.name,a.money,b.mail
from
var_a
left join var_b
Upvotes: 0
Views: 51
Reputation:
Not to be rude, but this one comes up pretty easily from some searches... all leading to the MySQL manual page: http://dev.mysql.com/doc/refman/5.7/en/user-variables.html
Not sure what you were searching on, but hope that helps... it has examples and all.
Upvotes: 1