2017-01-19 57 views
-1

喜我的問題左連接SQL查詢

contact_message表(1個數據)
-id
-messageid
-message
-date

列表contact_message數據
MySQL的左連接的SQL查詢列表中的解決方案

Array 
(
    [0] => Array 
     (
      [id] => 5 
      [messageid] => 1 
      [message] => A new e-mail 
      [date] => 2017-01-18 
     ) 

) 

contact_reply表(2數據)
-id
-messageid
-reply
-date
列表contact_reply數據

Array 
(
    [0] => Array 
     (
      [id] => 1 
      [messageid] => 5 
      [reply] => Thanks I save mail adress 
      [date] => 2017-01-18 
     ) 

    [1] => Array 
     (
      [id] => 1 
      [messageid] => 5 
      [reply] => Sorry What is your name ? 
      [date] => 2017-01-18 
     ) 

) 


SQL查詢

SELECT im.message,im.date,ic.reply,ic.date 
     from contact_message as im 
     left join contact_reply as ic 
     on im.id=ic.messageid 
     where im.messageid=:siral 


結果

Array 
(
    [0] => Array 
     (
      [message] => A new e-mail 
      [date] => 2017-01-18 
      [reply] => Thanks I save mail adress İSMAİL ÇİLOĞLU 
     ) 

    [1] => Array 
     (
      [message] => A new e-mail 
      [date] => 2017-01-18 
      [reply] => Sorry What is your name ? 
     ) 

) 

正常[1] INDIS消息null值,但寫的[0] INDIS [消息]值
我想結果

Array 
    (
     [0] => Array 
      (
       [message] => A new e-mail 
       [date] => 2017-01-18 
       [reply] => Thanks I save mail adress İSMAİL ÇİLOĞLU 
      ) 

     [1] => Array 
      (
       [message] =>null 
       [date] => 2017-01-18 
       [reply] => Sorry What is your name ? 
      ) 

    ) 
+0

對不起,但我不確定你在問什麼。 –

+0

joe C. sql查詢結果[1]消息列通常爲空但寫[0] indis mesage列值:( –

+0

對不起,我的中間和不好:/ –

回答

0

你的表結構似乎是不正確

Contact_message table (1 data) 
-id 
-messageid 
-message 
-date 

contact_reply表(2數據)

-id 
-contact_message_id // Foreign Key of table1 
-reply 
-date 

Sql查詢

SELECT im.message,im.date,ic.reply,ic.date 
    from contact_message as im 
    left join contact_reply as ic 
    on im.id=ic.contact_message_id 
    where im.messageid=:siral 
+0

遺憾相同的結果:( –

+0

陣列 ( [0] =>數組 ( [消息] =>新的電子郵件 [日期] => 2017年1月18日 [回覆] =>由於我保存郵件ADRESS ISMAILÇİLOĞLU ) [1] =>數組 ( [消息] =>新的電子郵件 [日期] => 2017年1月18日 [reply] =>對不起你叫什麼名字? ) ) –

+0

您期待什麼輸出? –