简体   繁体   中英

how to get column from third table with sql

$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";

I have another table meeting_time_poll containing these columns :

poll_id
meeting_id
poll_closed
poll_dates
poll_times

I need the poll_id where meeting_time_poll.meeting_id=meeting.meeting_id How can I put it in the sql?

Note: not all meeting_id from table meeting have a corresponding in meeting_time poll

How about this?

$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";

Also I would suggest using JOIN .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM