如果是取ID最大的,SELECT
h.id,
h.username,
h.qname,
h.qsex,
h.nian,
h.sg,
h.hy_sf,
p.photo
from hy h ,
(Select * from hy_photo Where Id In (Select Max(id) from hy_photo)) p
where h.username=p.username
h.id,
h.username,
h.qname,
h.qsex,
h.nian,
h.sg,
h.hy_sf,
p.photo
from hy h ,
(Select * from hy_photo Where Id In (Select Max(id) from hy_photo)) p
where h.username=p.username
h.username username ,
h.id id ,
h.qname qname,
h.qsex qsex,
h.nian nian,
h.sg sg,
h.hy_sf hy_sf,
p.photo photo,
p.dj dj
from
hy h ,
hy_photo p
where
h.username=p.username
and
p.id = (select top 1 id from hy_photo where username=p.username order by dj desc)
SELECT
h.id,
h.username,
h.qname,
h.qsex,
h.nian,
h.sg,
h.hy_sf,
p.photo
from hy h ,
(Select A.* from hy_photo A Inner Join (Select hy_id,Max(dj) from hy_photo Group By hy_id) B On A.hy_id=B.hy_id) p
where h.username=p.username
select A.id,A.username,A.qname,A.qsex,A.nian,A.sg,A.hy_sf,B.photo,max(B.dj) from hy A INNER JOIN hy_photo B on A.username=B.username group by A.id,A.username,A.qname,A.qsex,A.nian,A.sg,A.hy_sf,B.photo
h.qname qname,h.qsex qsex,h.nian nian,
h.sg sg,h.hy_sf hy_sf, p.photo photo
from hy h ,hy_photo p
where h.username=p.username
and not exists(
select * from hy_photo
where username=p.username
and dj>p.dj)
h.qname qname,h.qsex qsex,h.nian nian,
h.sg sg,h.hy_sf hy_sf, p.photo photo
from hy h ,hy_photo p
where h.username=p.username
and not exists(
select * from hy_photo
where username=p.username
and (dj>p.dj or dj=p.dj and id<p.id))
谢谢大家了.只是, zjcxc(邹建) 大哥,能不能问一下:
where h.username=p.username
and not exists(
select * from hy_photo
where username=p.username
and (dj>p.dj or dj=p.dj and id<p.id))
中的not exists()是什么意思呢.
:)
我的帖子已经结了.
可是又有新问题了.
如果,hy里面有d会员,但是,d会员没有照片,我还是要显示d会员怎么办呢
SQLrec="SELECT h.username username ,h.id id ,h.qname qname,h.qsex qsex,h.nian nian, h.sg sg,h.hy_sf hy_sf, p.photo photo ,p.dj dj from hy h ,hy_photo p where h.username(+)=p.username and not exists( select * from hy_photo where username=p.username and (dj>p.dj or dj=p.dj and id<p.id))"
我用外链接怎么会不对呢.能不能再帮我一次.
SELECT
h.id,
h.username,
h.qname,
h.qsex,
h.nian,
h.sg,
h.hy_sf,
p.photo
from hy h
Left Join
(Select A.* from hy_photo A Inner Join (Select hy_id,Max(dj) from hy_photo Group By hy_id) B On A.hy_id=B.hy_id) p
On h.username=p.username
邹老大的方法并不是很好的
left join hy_photo p on h.username(+)=p.username and not exists(select * from hy_photo where username=p.username and (dj>p.dj or dj=p.dj and id<p.id))