D
D
DenKapone2015-11-17 12:27:19
MySQL
DenKapone, 2015-11-17 12:27:19

Selecting unique records by two fields?

There is a message board

|кто |кому  |text |

|паша|маша  |text | 
|маша|паша  |text | 
|коля|маша  |text | 
|паша|сережа|text | 
|юра |паша  |text | 
|паша|света |text |

The task is to get the unique names of all Pasha's interlocutors, in one request, that is, those who wrote to him and those to whom he wrote.
It seems to me that it is very simple, but I can not find a way.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mletov, 2015-11-17
@DenKapone

SELECT name
FROM
(
SELECT Кто AS name
FROM Table
WHERE Кому='Паша'
UNION
SELECT Кому
FROM Table
WHERE Кто='Паша'
) AS t1
GROUP BY name

A
Andrey Dyrkov, 2015-11-17
@VIKINGVyksa

Use distinct

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question