log
id user productselect distinct l.user,l.product from log l where l.user in(
select distinct l1.user from log l1,log l2 where l1.id!=l2.id and l1.user=l2.user and l1.product='P1' 
 and l2.product='P2' )

解决方案 »

  1.   

    我是mysql4 好像不支持这种嵌套的select吧
      

  2.   

    表结构不是很重要吧  用户表的userid与产品表的userid关联嘛
    然后就是产品表里面有产品的信息 就这么2个表来查询  
      

  3.   

    select u.userid,p.pname
    from users u,products p
    where u.userid=p.userid
    and (p.pname='产品1' or p.pname='产品2')
      

  4.   

    不好意思想错了为是买了产品1或者2的用户去了select userid from users
    where userid in
       (
       select userid from products
       where pname="产品1"
       )
    and userid in
       (select userid from products
        where pname="产品2"
       )
      

  5.   

    gs6fox  我想问你一下  到底mysql4可以用这种嵌套的select不  好像有人说是不可以的啊
      

  6.   

    嵌套查询又不是啥高级特性,mysql4支持的,lz多虑了
      

  7.   

    mysql4就是不支持啊  郁闷 有谁有其他的方法吗?
      

  8.   

    偶在mysql4建表运行通过了 版本4.1.9
    不知lz怎么弄的