简体   繁体   English

如何获取属于用户的所有记录并仅显示具有不同名称的记录?

[英]How do I fetch all records which belong to a user and show only the records with distinct name?

Tagmap.where(user_id: current_user.id).uniq(:name)

This query doesn't seem to work. 此查询似乎不起作用。 It still fetches all the records belonging to that user only. 它仍然仅获取属于该用户的所有记录。

您可以使用group by SQL查询。

Tagmap.where(user_id: current_user.id).group(:name)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何仅获取与JPA中的其他2个表具有@OneToMany关系的父记录 - How do I Fetch Only Parent Records which has @OneToMany Relation with 2 other tables in JPA 如何编写查询以查找不属于所选字段的记录? - How to write a query to find records which do not belong the field selected? 我如何只提取所有电子邮件条目丢失的记录 - how do i extract only the records with all email entries missing 如何仅选择列中前 50 个不同值的所有记录 - How to select all records for only the first 50 distinct values in a column MYSQL选择不显示所有记录 - MYSQL select distinct does not show all records 如何获取 mysql 中具有最大日期值的那些行的记录? - How do I fetch the records of those rows which have the maximum date value in mysql? 获取不属于列表的mySQL记录 - Fetch mySQL records which do not fall in list 我如何在比较列中的两个相似记录时获取徽章详细信息和用户详细信息 - How do i fetch Badge details and User details while comparing two similar records in a Column 如何显示不同的记录,我想检查:如果表中已经存在blueid,则该数据仅在特定日期显示一次 - how to display distinct records, I want to check : if blueid is already present in the table show that data only once with particular date 如何在表格中显示所有记录? - How do I display all records in a table?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM