日期:2014-05-18  浏览次数:20765 次

2表查询取唯一问题
pnews表
----------------------------------
pnewsid     title         source       appenddate
12 123 123 2007-01-26   17:14:48.000
13 12 中心 2007-01-26   00:00:00.000
14 111 1 2007-01-26   00:00:00.000
15 11 中心 2007-01-26   00:00:00.000
16 11 中心 2007-01-26   00:00:00.000
17 1212 中心 2007-01-26   00:00:00.000
18 1212 中心 2007-01-26   00:00:00.000
19 1212 中心 2007-01-26   00:00:00.000
20 323 中心 2007-01-26   00:00:00.000
21 1··1 中心 2007-01-26   00:00:00.000

pictures表
-----------------------------------
pid           pnewsid           pname                         pintr                         place
21 12 noimage.gif                     1
22 12 noimage.gif 无介绍                     0
23 13 noimage.gif 无介绍                     0
24 14 4ced4.gif                 上铺image                     1
25 14 f58f0f.jpg   iyang                     2
26 14 adbfe4.jpg you   yige   taiyang   3
27 14 4ced4.gif                     1                     0
28 14 4ced4.gif       2                     0
29 14 4ced4.gif                     3                     0
30 14 4ced4.gif                     4                     0
31 14 4ced4.gif             5                     0

-----------------------

我现在想要的结果就是
pictures表里头去掉pnewsid这个字段重复的记录,然后跟pnews表里头的title字段的组合

形式如:
------------------------------
pid             pnewsid               title                           pname
22 12           123                             noimage.gif
23 13             12                           noimage.gif
24 14           111                             4ced4.gif  


万分感谢!!!            


------解决方案--------------------
select distinct pid , pnewsid , title , pname
from (select ... from pictures,pnews where pnews.pnewsid=pictures.pnewsid) a
------解决方案--------------------
select m.* , n.* from pnews m,
(