开发者

Nested select in mysql v 3.23

I want wr开发者_如何学编程ite this sql select statment in mysql v 3.23

select * 
    from radacct 
    where username in ( 
        select username 
            from radcheck 
            where Attribute = 'max-weekly-session'
    );

but say

ERROR 1064: You have an error in your SQL syntax near 
'select username from radcheck where Attribute= 'max-weekly-session')' 
at line 1

in mysql v 5 this is ok but how can I do in v 3.23?


nested selects are not available in MySQL version < 4.1

following will work

select radacct.* 
from radacct inner join radcheck on radacct.username = radcheck.username 
where radcheck.Attribute= 'max-weekly-session'


try this:

select a.* 
from radacct a 
join radcheck b on a.username = b.username
where b.Attribute = 'max-weekly-session'


Full standards-compliant support for subqueries was added in 4.1. Prior to that, you had to use JOINs and other workarounds to achieve the same effect.

See 12.2.8.11. Rewriting Subqueries as Joins for Earlier MySQL Versions


select * 
from radacct ra
inner join radcheck on ra.username = rc.username
where rc.Attribute = 'max-weekly-session'


I needed something similar but all solutions given here cause a bug were multiple entries are returned from radacct. I've fixed this by adding a group by on the radacct key.

select ra.* 
from radacct ra
inner join radcheck rc on ra.username = rc.username
where rc.Attribute = 'max-weekly-session'
group by ra.Id
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜