mysql - 从表中选择两次 PHP SQL

标签 mysql join

我有一个大问题,无法解决: 我有一个表(操作),每行存储两个 id 属于用户。一种针对客户,另一种针对服务提供商。

enter image description here

这些用户的姓名和家庭位于另一个可以获取的表(tablesite)中。但我不知道如何获取客户的姓名和家庭以及 service_providers 的家庭名称。

enter image description here

结果应该是这样的: 示例:第一行 service_provider_id是 33 和 customer_id是 34 所以我需要这个:

service_provider: sajad khammar --- customer: akbar ahmadi 

最佳答案

SELECT
    a.job_id,
    CONCAT( s.name, ' ', s.family ) AS service_provider,
    CONCAT( c.name, ' ', c.family ) AS customer
FROM action a
INNER JOIN tablesite s
    ON a.service_provider = s.id_user
INNER JOIN tablesite c
    ON a.customer_id = c.id_user

关于mysql - 从表中选择两次 PHP SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33598016/

相关文章:

php - Laravel 4.2 Eloquent : How can i return the count of id based on the following query?

mysql group by 加入列太慢

mysql - 获取 'JOIN and WHERE' 情况下的 COUNT(*)

mysql - 修复错误 1241 操作数应包含 1 列

mysql - 查询异常(23000)SQLSTATE [23000] : Integrity constraint v1452

MySQL 左连接与交叉连接查询问题

SQL - 获取最大值

sql-server - SQL Server : Multiple table joins with a WHERE clause

java - HQL 左连接条件

mysql - SQL:所有类别放入单个列中