SQL 不同关键字问题
我正在从两个表中获取数据。但我得到了不需要的重复,所以我希望不同的关键字只获取不同的记录,但它不起作用
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 项必须出现在选择列表中。
我缺少什么。非常感谢任何形式的帮助。
I am fetching data from two tables. but i am getting unwanted repeatation so i want the distinct keyword to get only distinct records but it did not work
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
The error:
Msg 145, Level 15, State 1, Line 1
ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
What I am missing. Any kind of help is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 astlander 提到的,如果您按特定字段排序,则该字段必须在 select 语句中列出。将 *fb_event.eventid* 添加到您的选择中,您的选择语句应该没问题。
As astlander mentions, if you're ordering by a particular field, that field must be listed it in the select statement. Add *fb_event.eventid* to your select, and your select statement should be fine.