Remove IDs without repeating a table with SQL

1

see, I have a table in SQL called messages , this table contains 2 IDs, one of the receiver and another of the issuer, the date and the message itself.

I try to extract with what people have spoken, for example, the member with id 1 but when I do the query I get this:

Is there any way that only the IDs come out without repeating and in a single column?

Thank you.

    
asked by Kristofer Soler 16.01.2018 в 18:27
source

1 answer

0

This could solve your problem, in a very simple way:

Query:

SELECT id as idsConQuienHablo FROM (
  SELECT m1.miembo_id_emisor as id FROM mensaje as m1 WHERE miembo_id_emisor != 1
     UNION
  SELECT  m2.miembo_id_receptor as id FROM mensaje as m2 WHERE miembo_id_receptor != 1
)
  

UNION: without (ALL) removes duplicates between columns with the same   name.

    
answered by 16.01.2018 / 18:46
source