mysql - Return row from subselect -


i have mysql db scheme:

users (id, login) coins (userid, value, curr) 

i need write select return result: login , max coin have , currency of coin.

i've tryed that:

select login,  (   select value, curr   coins    coins.userid = users.id   order value desc   limit 1 ) row(value, curr) users 

its not working... i'll recieve error, "operand should contain 1 column(s)". expected it, dont know way, how make it.

so guess: there way return multiple-column-single-line (row) subquery parent query?

(yes, can use 2 subqueries, not effective.)

thanks time.

select u.login, g.maxval, c.curr users u join coins c on u.id = c.userid    join (     select userid, max(`value`) maxval     coins     group userid   ) g on c.userid = g.userid , c.value = g.maxval  

in case of ties, above query return coins highest value, if want select 1 of coins, can add group by outer query:

select u.login, g.maxval, c.curr users u join coins c on u.id = c.userid    join (     select userid, max(`value`) maxval     coins     group userid   ) g on c.userid = g.userid , c.value = g.maxval  group c.userid 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -