【问题标题】:Order rows by column in joined table in Postgres在 Postgres 的联接表中按列对行进行排序
【发布时间】:2021-02-12 20:54:46
【问题描述】:

我正在尝试按用户的名字升序对我的friend_profile 表中的行进行排序(加入的用户表中的列)。

此查询获取我需要的结果,但是如何根据用户表中的 first_name 字段维护friend_profiles 行的顺序?

SELECT * 
FROM friend_profile 
JOIN user ON friend_profile.id = user.id 
WHERE user.id IN (id1, id2, etc.);

【问题讨论】:

  • 你试过了吗:按名字排序

标签: sql postgresql join


【解决方案1】:

添加到查询的末尾ORDER BY user.first_name ASC。 在这里查看更多帮助https://www.postgresqltutorial.com/postgresql-order-by/

【讨论】:

  • 没有意识到它和连接一样简单。谢谢!
猜你喜欢
  • 2017-11-09
  • 2012-04-10
  • 2021-01-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-05
  • 1970-01-01
相关资源
最近更新 更多