如果有有一个集合user,里面的数据如下:
userid  username
   1       a
   2       b
,另外一个集合评论comment,里面的数据如下:
id  userid  commenttitle  commentconttent
 1    1          测试           测试
 2    2          测试2          内容2
我怎么能一次查询出username,commenttitle,commentconttent这样的数据呢?

解决方案 »

  1.   

    select * from `user` a inner join `comment` b on b.userid=a.userid
      

  2.   

    注意:我这个是mongodb数据库。
    存储结构是:
    user:{  
    "userid ": 1,
    "username": "a"


    {  
    "userid" : 2,
     "username": "b"

    comment:
    {  
    "userid":1,
    "commenttitle":"测试",
    "commentconttent": "测试",


    {  
    "userid":2,
     "commenttitle": "测试2",
     "commentconttent":"测试2",}
    不是用select来查询的
      

  3.   

    注意:我这个是mongodb数据库。
    存储结构是:
    user:{  
    "userid ": 1,
    "username": "a"


    {  
    "userid" : 2,
     "username": "b"

    comment:
    {  
    "userid":1,
    "commenttitle":"测试",
    "commentconttent": "测试",


    {  
    "userid":2,
     "commenttitle": "测试2",
     "commentconttent":"测试2",}
    不是用select来查询的