我正在开发类似应用程序的火种,我想获取所有匹配项。在我的匹配表中,每个用户都有自己的条目。所以对于一个匹配项,有两个用户,表中总共有两个条目。
我尝试了如下所示的 sql 查询
select user_id, friend_id from matches where is_match = 1 group by user_id,friend_id
通过查询我得到低于结果`
|--------------------------|
|user_id|friend_id|is_match|
|--------------------------|
| 23 | 24 | 1 |
|--------------------------|
| 24 | 23 | 1 |
|--------------------------|
| 24 | 25 | 1 |
|--------------------------|
| 25 | 24 | 1 |
|--------------------------|
| 25 | 26 | 1 |
|--------------------------|
| 26 | 25 | 1 |
---------------------------
`
我想要这样的结果。
`
|--------------------------|
|user_id|friend_id|is_match|
|--------------------------|
| 23 | 24 | 1 |
|--------------------------|
| 24 | 25 | 1 |
|--------------------------|
| 25 | 26 | 1 |
|--------------------------|
`