0

有人可以帮我处理这个 SQL,因为我看到错误消息为未知列,我知道该列在那里?

SELECT 
   statut.*, 
   clien_1.Id, clien_1.mail, clien_1.nom, clien_1.prenom, 
   image_profil_1.image, 
   statut_comments.*, 
   clien_2.Id, clien_2.mail, clien_2.nom, clien_2.prenom, 
   image_profil_2.image  
FROM  
    statut
INNER JOIN 
    clien AS clien_1 ON statut.client_from = clien_1.Id
INNER JOIN  
    clien AS clien_2 ON statut_comments.id_client = clien_2.Id
INNER JOIN  
    statut_comments ON statut_comments.comment_id = statut.id
INNER JOIN 
    image_profil AS image_profil_1 ON image_profil_1.mail = clien_1.Id 
INNER JOIN 
    image_profil AS  image_profil_2 ON image_profil_2.mail = clients_2.Id  
4

2 回答 2

2

问题在于您的内部连接的顺序 - 您在加入之前使用 blog_statut_comments。

尝试更改连接的顺序。

于 2012-08-25T20:16:52.937 回答
0

正如 Fiona 已经指出的那样 - 您指statut_comments的是在它被添加到连接表列表之前。不确定我是否“明白了” - 这是一个直观的解释:

在此处输入图像描述

你基本上需要改变你的顺序JOINs

SELECT 
   (your list of columns)
FROM  
    statut
INNER JOIN     -- include the "status_comments" *BEFORE* refering to it!
    statut_comments ON statut_comments.comment_id = statut.id
INNER JOIN 
    clien AS clien_1 ON statut.client_from = clien_1.Id
INNER JOIN  
    clien AS clien_2 ON statut_comments.id_client = clien_2.Id
INNER JOIN 
    image_profil AS image_profil_1 ON image_profil_1.mail = clien_1.Id 
INNER JOIN 
    image_profil AS  image_profil_2 ON image_profil_2.mail = clients_2.Id  
于 2012-08-25T21:16:47.900 回答