0
我試圖在MySql查詢中插入來自兩個不同表的「標題」。如果我嘗試下面的第一個查詢,它會起作用。一旦我添加第二個LEFT JOIN
,它仍然獲得第一個「博客」標題,但沒有拿到第二個「專輯」標題。關於如何從兩個表中獲得兩個標題的任何想法?請注意,我需要確保我有這兩個條件在那裏每個:updates.ref_table = 'albums' AND updates.ref_id = albums.id
單個MySQL查詢中的兩個LEFT JOIN
作品...
$query = "SELECT updates.*, albums.title FROM updates ";
$query .= "LEFT JOIN albums ON updates.ref_table = 'albums' AND updates.ref_id = albums.id ";
$query .= "WHERE user_id = ".$user_id." ORDER BY date DESC";
Doen't工作...
$query = "SELECT updates.*, albums.title, blog.title FROM updates ";
$query .= "LEFT JOIN blog ON updates.ref_table = 'blog' AND updates.ref_id = blog.id ";
$query .= "LEFT JOIN albums ON updates.ref_table = 'albums' AND updates.ref_id = albums.id ";
$query .= "WHERE user_id = ".$user_id." ORDER BY date DESC";
非常感謝您的幫助:) – Chris