我有两张桌子如下-
表1
mysql>从访问ID中选择*;

+------------+----------------+
| SERVICE_ID | ACCESS_LIST_ID |
+------------+----------------+
|       1035 |           1040 |
|       1094 |           1134 |

表2
mysql>从配置文件中选择*;
+-------+------------------------+-------------+-
| PR_ID | PR_NAME                | PR_PARENTID | PR_TYPE           |
---------------------------------------------------------------------
|  1035 | raj                    |        1022 | name           |
|  1040 | computer               |        1035 | course         |
|  1094 | suresh                 |        1077 | name           |
|  1134 | electronics            |        1077 | course         |

我需要以下输出
桌子
| raj      |  computer  |
| suresh   | electronics|

最佳答案

可能是这样的

SELECT T2.PR_NAME AS NAME,T3.PR_NAME AS Serveice
FROM Access_ID T1 JOIN PROFILE T2 ON T1.SERVICE_ID = T2.PR_ID
                  JOIN PROFILE T3 ON T1.ACCESS_LIST_ID = T3.PR_ID

FIDDLE DEMO
输出将是
  +---------+-------------+
  | NAME    | SERVEICE    |
  +---------+-------------+
  | raj     | computer    |
  | suresh  | electronics |
  +---------+-------------+

10-07 23:07