我从两个表中获取数据。但我得到了不必要的重复,所以我希望distinct关键字只获得不同的记录,但它不起作用
SELECT distinct fb_event.id AS rid, fb_event.eventname AS sevntname,
fb_event.location AS slocation, fb_event.startdate AS sstartdate,
fb_event.enddate AS senddate,
cast(fb_event.CATEGORY as text) AS sCATEGORY, cast(fb_event.tags as text) AS stags,
cast(fb_event.description as text) AS sdescription,
cast(fb_event.eventid as text) AS seventid,
cast(fb_event.city as text) AS scity, cast(fb_event.venue as text) AS svenue,
cast(fb_event.country as text) AS scountry, cast(fb_event.postalcode as text) AS spostalcode,
cast(fb_event.keyword as text) AS skeyword,
cast(fb_userevents.userid as text) AS suserid,fb_event.longitude as long, fb_event.altitude as alt,fb_event.attending
FROM fb_event INNER JOIN
fb_userevents ON fb_event.eventid = fb_userevents.eventid order by fb_event.eventid
错误: 消息145,第15级,状态1,第1行 如果指定了SELECT DISTINCT,则ORDER BY项必须出现在选择列表中。
我缺少什么。非常感谢任何形式的帮助。
答案 0 :(得分:0)
正如astlander所提到的,如果您按特定字段进行排序,则该字段必须在select语句中列出。将* fb_event.eventid *添加到您的选择中,您的选择语句应该没问题。