SQL 不同关键字问题

发布于 2024-12-03 10:31:09 字数 1278 浏览 2 评论 0原文

我正在从两个表中获取数据。但我得到了不需要的重复,所以我希望不同的关键字只获取不同的记录,但它不起作用

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

像你 2024-12-10 10:31:09

正如 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文