简体   繁体   English

如何从没有匹配列的表中获取数据?

[英]How to get data from table with no matching column?

I've been bumping my head over trying to find the perfect query that will allow me to display the first and last names of all people involved in a conversation about a specific project. 我一直在努力寻找一个完美的查询,使我能够显示参与有关特定项目的对话的所有人的姓氏和名字。

conversations table 对话表

convo_id | project_id | toEmployee_id | fromEmployee_id | message

employees 雇员

employee_id | first_name | last_name |

myinbox.php 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 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'

While it all work great at displaying specific project conversation with the people involved, I would like to be able to display their name rather their employee_id . 尽管这一切都能很好地显示与相关人员的特定项目对话,但我希望能够显示他们的姓名而不是他们的employee_id

How can I do that? 我怎样才能做到这一点?

join employees table twice, one for toEmployee_id and one for fromEmployee_id like so: toEmployee_id employees表两次,一次用于toEmployee_id ,一次用于fromEmployee_id如下所示:

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
JOIN employees AS emp
    ON emp.employee_id = epc.toEmployee_id
JOIN employees AS emp2
    ON emp2.employee_id = epc.fromEmployee_id
WHERE
    epc.project_id='$projectconvoid'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从具有2列匹配mysql的3个表中获取结果 - Get result from 3 table with 2 column matching mysql 根据与另一个表匹配的数据更新表中的列 - Updating a column in table from matching data with another table 如何从另一个表中将2个字段匹配到另一个表中相同1个字段的数据 - How to get data from another table matching 2 fields to same 1 field from another table 如何使用JavaScript从表中获取任何特定的列数据? - How to get any specific column data from a table using JavaScript? MySQL:从其他与ID匹配的表中获取数据 - MySQL: Get data from other table matching the ids 从另一个与名称 laravel 匹配的表中获取数据 - get data from another table matching with name laravel 从表的列中获取数据并存储到另一个表的列 - Get data from column of a table and store to column another table 如何在PHP Codeigniter中从一个表中获取特定列,并从另一表中获取所有其他数据 - How to get specific column from one table and all other data from other table in php codeigniter Mysql 来自另一个表的逗号分隔列匹配 - Mysql commaseparated column matching from another table 如何从第二个表中获取与第三个表共同的数据列,而第三个表在第一个表上有共同点? - How to get data column from second table that have common to the third table which third table have common on the first table?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM