我有一个名为-g
的表,它有2个外键:tbl_appointment
和idclient
,它们引用idemployee
。
所以我想做的不是获取tbl_persons
id
和idclient
的{{1}},而是希望获得属于那些idemployee
的{{1}}名称
查询
(name,last_name,last_sname)
答案 0 :(得分:2)
尝试以下
SELECT
app.*,
CONCAT(client.name,' ',client.last_name,' ',client.last_sname) AS client_full_name,
CONCAT(empl.name,' ',empl.last_name,' ',empl.last_sname) AS empl_full_name
FROM tbl_appointment app
LEFT JOIN tbl_persons client ON app.idclient=client.id
LEFT JOIN tbl_persons empl ON app.idemployee=empl.id
WHERE app.idclient= '$user'
答案 1 :(得分:2)
您可以使用LEFT JOIN
代替 <h1>Concatenation Challenge</h1>
<table>
<tr>
<td>All days of the week</td>
<td id="demo2"></td>
</tr>
</table>
INNER JOIN
答案 2 :(得分:0)
尝试以下代码:只有你必须分别选择客户和员工,一起更难
SELECT name,last_name,last_sname
FROM tbl_persons WHERE id IN (
SELECT DISTINCT idclient FROM tbl_appointment;
); -- This will select all the clients
SELECT name,last_name,last_sname
FROM tbl_persons WHERE id IN (
SELECT DISTINCT idemployee FROM tbl_appointment;
); -- This will select all the employees