gpt4 book ai didi

mysql - DISTINCT语句如何合并一个表中的两行

转载 作者:行者123 更新时间:2023-11-29 01:19:40 25 4
gpt4 key购买 nike

请给出任何解决方案如何合并一张表中的两行然后如何使用不同

查询:

select distinct  uid , r_uid from messenger  where uid=213 or r_uid =213 

我得到了这样的输出

      uid     r_uid
--------------
213 239
239 213
-----------------

但我们需要这样

           new id
-----------
239
---------

请给我任何解决方案,我是 MySQL 的新手,在此先感谢

最佳答案

使用union:

select uid as new_id from messenger
where uid = 213
union
select r_uid from messenger
where r_uid = 213;

关于mysql - DISTINCT语句如何合并一个表中的两行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50173772/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com