2016-02-04 72 views
0

我已經創建了一個使用連接的mysql查詢在其中我得到了彼此進行聊天的朋友列表。該查詢包含三個表。現在想要添加來自包含用戶聊天的第4表的計數。我在該表中有一個列名readstatus,我在該表中檢查消息是否被讀取。現在我想補充一點,表的計數在此查詢,但我沒有得到正確的方法添加此這裏是查詢從SQL查詢中的另一個表中添加計數

SELECT c.c_id, u.first_name, u.last_name, u.user_name, u.online_status, c.user_one, c.user_two, u.user_img, c.property_id, p.locality, p.city 
FROM cpo_conversation c, 
     property_register u, 
     property_for_sale p 
WHERE CASE WHEN c.user_one = '19' THEN c.user_two = u.id 
      WHEN c.user_two = '19' THEN c.user_one = u.id END 
     (c.user_one = '19' OR c.user_two = '19') AND p.id = c.property_id 
ORDER BY c.c_id DESC 
+0

請張貼4表結構 –

回答

0
SELECT (SELECT COUNT(*) from ***4th_table*** WHERE ***user_condition*** AND readstatus=1) as your_count, c.c_id, u.first_name, u.last_name, 
u.user_name, u.online_status, c.user_one, c.user_two, u.user_img, 
c.property_id, p.locality, p.city FROM cpo_conversation c, property_register 
u, property_for_sale p WHERE CASE WHEN c.user_one = '19' THEN c.user_two = 
u.id WHEN c.user_two = '19' THEN c.user_one = u.id END (c.user_one = '19' OR 
c.user_two = '19') AND p.id = c.property_id ORDER BY c.c_id DESC 
+0

用戶情況是這樣的: 4th_table .userid = u.id –

+0

感謝您的幫助 –

相關問題