我一直在試圖找到一個完美的查詢,讓我能夠顯示所有參與關於特定項目的對話的人的名字和姓氏。如何從沒有匹配列的表中獲取數據?
對話表
convo_id | project_id | toEmployee_id | fromEmployee_id | message
員工
employee_id | first_name | last_name |
myinbox.php
SELECT * FROM projects as p
JOIN employeeprojects AS ep
ON p.project_id = ep.project_id
JOIN employees AS e
ON ep.assigned_by = e.employee_id
JOIN clients AS c
ON p.client_id = c.id
WHERE ep.employee_id='$session_myemployeeid'
<a data-toggle="tooltip" title="view conversation" href='conversation_feed.php?viewproject=conversation&emprojectid=<?=$employeeproject['project_id'];?>View Conversation</a>
displayconversation.php
$projectconvoid = $_GET['emprojectid'] ;
SELECT * FROM employeeprojects_conversation AS epc
JOIN projects AS p
ON epc.project_id=p.project_id
JOIN employeeprojects AS ep
ON p.project_id=ep.project_id
WHERE epc.project_id='$projectconvoid'
雖然這一切工作,在顯示與參與的人具體項目的談話很棒,我想能夠比較他們的employee_id
顯示他們的名字。
我該怎麼做?
加入員工表。並縮進你的SQL – Ibu
就像你以前的查詢所做的那樣,'JOIN employees AS e ON ep.assigned_by = e.employee_id' – chris85
@ chris85:是的,我想這樣做。這個查詢FROM和TO的東西顯示了assigned_the_project的僱員的名字。 –