如何使用sql从第三个表中获取列

时间:2012-06-25 08:25:21

标签: mysql

$sql = "SELECT m.*,p.place_title
                FROM members_meetings mm,meetings m,places p
                WHERE mm.meeting_id=m.meeting_id AND mm.member_id=$member_id AND m.cat_id=$cat_id AND m.place_id=p.place_id AND m.meeting_status<>0
                ORDER BY mm.meeting_id DESC";

我有另一个表meeting_time_poll包含这些列:

poll_id
meeting_id
poll_closed
poll_dates
poll_times

我需要poll_id,其中meeting_time_poll.meeting_id = meeting.meeting_id 我怎么能把它放在sql中?

注意:并非所有来自桌面会议的meeting_id在meeting_time民意调查中都有对应

1 个答案:

答案 0 :(得分:0)

这个怎么样?

$sql = "SELECT m.*,p.place_title, mp.poll_id
            FROM 
                members_meetings mm,
                meetings m,places p, 
                meeting_time_poll mp
            WHERE 
                mm.meeting_id=m.meeting_id
                AND mm.member_id=$member_id 
                AND m.cat_id=$cat_id 
                AND m.place_id=p.place_id 
                AND m.meeting_status<>0 
                AND mp.meeting_id=m.meeting_id
            ORDER BY mm.meeting_id DESC";

我也建议使用JOIN