Specific merge 2 columns in sql excluding one of them

后端 未结 2 592
再見小時候
再見小時候 2021-01-28 07:56

I have table like this:

| user1 | user2 |
|   1   |   2   |
|   3   |   1   |
|   4   |   1   |
|   1   |   5   |
|  ...  |  ...  |

I wanna mer

相关标签:
2条回答
  • 2021-01-28 08:27
    SELECT user1 AS users FROM `table` WHERE user1 NOT IN (SELECT user2 FROM `table`)
     UNION 
    SELECT user2 AS users FROM `table` WHERE user2 NOT IN (SELECT user1 FROM `table`)
    ORDER BY users
    
    0 讨论(0)
  • 2021-01-28 08:38
    SELECT IF(user1 = 1, user2, user1) AS user
    FROM table
    WHERE user1 = 1 OR user2 = 1
    
    0 讨论(0)
提交回复
热议问题