Mysql add variable in select statement -
i have query this
select a.id col1, b.id col2, b.title col3 tbl1 inner bring together tbl2 b on a.tbl2_id=b.id
this query working properly, if create subquery , pass value of col2, this
select a.id col1, b.id col2, b.title col3, ( select a.name tbl1 inner bring together tbl2 b on a.tbl2_id=b.id a.id= [value of col2] ) tbl1 inner bring together tbl2 b on a.tbl2_id=b.id
how can achived pass value of col2 in subquery? in advance
also can utilize mysql user-defined variables in order avoid multiple joins , maintain code "more readable"
select a.id col1, @mybcol2value := b.id col2, b.title col3, ( select a.name tbl1 inner bring together tbl2 b on a.tbl2_id = b.id a.id = @mybcol2value ) name tbl1 inner bring together tbl2 b on a.tbl2_id = b.id;
mysql select
No comments:
Post a Comment