-1

I have table which have createdby and publishedby columns.

These two get the same value(userId) some time.

Need a correct mysql query to get user ids without duplicating from two column.

like createdby column = 102,103,104

publisheby column = 103,105,104

excepted result - 102,103,104,105

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Nandhini
  • 15
  • 3
  • What types are these columns? Are the values really comma-delimited strings? – Mureinik Oct 26 '21 at 09:53
  • It might help https://stackoverflow.com/questions/635937/how-do-i-specify-unique-constraint-for-multiple-columns-in-mysql – abSiddique Oct 26 '21 at 09:56
  • 1
    Can you show us the code that insert's/updates these columns. Surely it can only be an error in the writing of the queries – RiggsFolly Oct 26 '21 at 09:57
  • The values are not comma-delimited strings. I'm just giving example. the column type bigint. I didn't give hear real datas. @Mureinik – Nandhini Oct 26 '21 at 11:10
  • Is it possible to get two columns values in single resultset without duplicate values? – Nandhini Oct 26 '21 at 11:13

1 Answers1

1

You can use the union set operator to get results from both columns and remove duplicates:

SELECT createdby 
FROM   mytable
UNION
SELECT publisheby
FROM   mytable
Mureinik
  • 297,002
  • 52
  • 306
  • 350