LEFT JOIN 請教

edited 十月 2013 in PHP新手區
查詢式1:
SELECT re_id , re_serial , re_parent_id FROM fourm_re_discuss WHERE re_id=157 order by re_time


結果:
<img src="http://home.pchome.com.tw/family/b90220208/mysql1.jpg">;



查詢式2:
SELECT r.re_id , r.re_serial , r.re_parent_id , c.re_serial AS father_serial_is FROM fourm_re_discuss r LEFT JOIN fourm_re_discuss c ON r.re_id=157 AND c.re_id=157 AND c.re_serial=r.re_parent_id AND c.re_serial=441 order by c.re_time


結果:
(圖片非全部我只擷取部分的 raw)
<img src="http://home.pchome.com.tw/family/b90220208/MYSQL.jpg">;



├128┤ <b><u>請教,</u></b>
如何修改可使上方 查詢式:2 僅列出 re_id=157 的 raw 呢?
(不用 limit)

原始討論: http://twpug.net/x/modules/newbb/viewtopic.php?topic_id=1077

評論

  • edited 十二月 2005
    這樣子如何?
    SELECT r.re_id , r.re_serial , r.re_parent_id , c.re_serial AS father_serial_is
    FROM fourm_re_discuss r, fourm_re_discuss c
    WHERE r.re_id = c.re_id AND c.re_serial=r.re_parent_id AND c.re_serial=441
    ORDER BY c.re_time AND r.re_id=157;
    
Sign In or Register to comment.