求sql语句,答案正确立即给分
有三个表,结构如下:
表1: customize_info:
(
id number(10) not null,
//这个publish_id与publish_info中的id对应
publish_id number(10) not null,
//这个user_id 与 user中的id对应
user_id number(10) not null,
status varchar2(1)
)
表2: publish_info:
(
id number(10) not null,
//这个user_id 与 user中的id对应
user_id number(10) not null,
msg varchar2(1024) not null
)
表3: user
(
id number(10) not null,
phone varchar2(20) not null
)
我现在想做的操作是这样的。
1:从表customize_info中取出status是null的记录
select id, publish_id, user_id userid1 from customzie_info where status is null
2:遍历上面的结果,对每一条记录做如下操作:
select phone from user where id = (value of userid1)
select user_id userid2,msg from publish_info where id = publish_id
select phone from user where id = (value of userid2)
我的问题是能不能查询一次数据库就把我所要的东西查出来呢?
我使用下面的语句:
select a.msg content ,b.phone fromphone, c.id infoid, d.phone tophone
from publish_info a ,user b ,customize_info c ,user d
where a.user_id = b.id
and a.id =c.publish_id
and d.id = c.user_id
and c.status is null
但结果是错的。(好象叉乘了)
正确的sql语句该怎么写?(或者不可能?)