简体   繁体   English

选择所有列值相同的行

[英]Select all rows where the value of column is the same

I have a table of users. 我有一个用户表。

I want to send emails of 'latest matches' - where a match is when two users live in the same country. 我想发送“最新匹配”的电子邮件-匹配是指两个用户居住在同一国家/地区。

This will be done by a cron job - not for each specific user when they are logged in. 这将由cron作业完成-不适用于每个特定用户登录后的情况。

The script needs to do this as a 'spectator' of the whole database. 该脚本需要作为整个数据库的“旁观者”来执行此操作。

How do I select all users with the same location? 如何选择具有相同位置的所有用户? Not by giving a value. 不是通过赋予价值。

Not: 不:

"SELECT * FROM users WHERE location = 'Germany';

But: 但:

"SELECT * FROM users WHERE something something something // where location is the same.

So that the query returns all users from germany in one group/array, all users from france in one group/array etc. 这样查询将返回来自德国的所有用户在一个组/阵列中,所有来自法国的用户在一个组/阵列中等等。

Also, if I'm not being too cheeky asking two in one, is there anything different in the way you handle the result in this type of query? 另外,如果我不是太厚脸皮地问二合一,那么在这种类型的查询中处理结果的方式是否有所不同? As There would be multiple arrays? 由于会有多个数组? Would it return one multi-dimensional array, which I can then choose to have returned as associative? 它会返回一个多维数组,然后选择该数组作为关联数组吗?

Thanks 谢谢

select location, group_concat(user_name) as users
from users
group by location

or simply iterate over the result that is ordered by location 或简单地迭代按位置排序的结果

select user_name
from users
order by location, username

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM