2

如果来自我的查询并且不知道如何解决我的查询,我会收到重复列名的错误

SELECT distinct(courseid+senderid+recipientid) as diskey,
       mess.id,
       User.firstName as recipientName,
       Course.name,
       senderid,
       recipientid,
       courseid,
       message,
       mess.status,
       mess.createdOn 
FROM 
(
    SELECT * 
    from Message,User,Course 
    where Message.recipientid=User.id 
        and Message.courseid=Course.id 
    order by Message.createdOn DESC
) as mess,
     User,
     Course 
WHERE senderid ='3' 
      OR recipientid='3' 
GROUP BY diskey;    

任何人都可以帮忙吗

4

4 回答 4

7

为避免重复使用其表为列名添加前缀,如下所示:

tab_name.col_name
于 2012-11-12T11:49:58.707 回答
0

尝试更换

WHERE senderid ='3' 
  OR recipientid='3' 

HAVING senderid ='3' 
  OR recipientid='3' 

快乐编码!

于 2013-01-21T09:02:27.573 回答
0
于 2012-11-12T11:55:09.973 回答
0

为了避免重复写入查询,如下使用前缀(tableName).columnname:

select id, name1,name2 from(
select table1.id,table1.name as name1, table2.name as name2 from
table1
innerjoin table2 on table1.id=table2.table1_id
)group by id
于 2013-07-12T10:37:23.237 回答