两个表的查询问题
表AAA中有字段xxname,xxpic,xxdate,xxlei,useid
表BBB中有字段xxusid,xxmonery,usid
现在想要得到结果是表AAA中xxlei=4,并且在表BBB中xxmonery
=2的前12条记录,
以下的查询是对的
select top 12 AAA.xxname,AAA.xxpic,AAA.xxdate,AAA.xxlei from (select * from AAA WHERE xxlei=4 ) AS AAA inner join BBB
on AAA.useid=BBB.usid where BBB.xxmonery=2 order by AAA.xxdate desc
但是
select top 12 AAA.xxname,AAA.xxpic,AAA.xxdate,AAA.xxlei from (select AAA.xxname,AAA.xxpic,AAA.xxdate,AAA.xxlei from AAA WHERE xxlei=4 ) AS AAA inner join BBB
on AAA.useid=BBB.usid where BBB.xxmonery=2 order by AAA.xxdate desc
以及
select top 12 AAA.xxname,AAA.xxpic,AAA.xxdate,AAA.xxlei from (select xxname,xxpic,xxdate,xxlei from AAA WHERE xxlei=4 ) AS AAA inner join BBB
on AAA.useid=BBB.usid where BBB.xxmonery=2 order by AAA.xxdate desc
都不对,我把*改成AAA.xxname,AAA.xxpic,AAA.xxdate,AAA.xxlei或者xxname,xxpic,xxdate,xxlei不可以吗?
------解决方案--------------------select top 12 AAA.xxname,AAA.xxpic,AAA.xxdate,AAA.xxlei,bbb.xxusid,bbb.xxmonery,bbb.usid
from AAA join bbb
on aaa.usid=bbb.usid
where aaa.xxlei=4 and bbb.xxmonery=2
------解决方案--------------------AS AAA 为什么还要as为AAA