我有四个表,结构如下:
a表           b表          c表         d表
p_id  date  p_id  date  p_id  date  p_id  date
当a,b,c,d的p_id相同时选出date来?

解决方案 »

  1.   

    select a.date as adate,b.date as bdate,c.date as cdate,d.date as ddate from a inner join b on b.p_id=a.p_id inner join c on c.p_id=a.p_id inner join d on d.p_id=a.p_id where 1
      

  2.   

    或者:
    select a.date as adate,b.date as bdate,c.date as cdate,d.date as ddate from a inner join b on b.p_id=a.p_id inner join c on c.p_id=a.p_id inner join d on d.p_id=a.p_id where 1 group by adate,bdate,cdate,ddata
    后面的 group by 楼主根据实际需要加。如果没有必要,可以不加
      

  3.   

    select a.date,b.date,c.date,d.date
    from a,b,c,d
    where a.id=b.id and b.id=c.id and c.id=d.id
    select a.date,b.date,c.date,d.date
    from ((a inner join b using id)
    inner join c using id)
    inner join d using id