Re: message table

From: Lennart Jonsson <erik.lennart.jonsson_at_gmail.com>
Date: Sat, 19 Sep 2015 14:18:05 +0200
Message-ID: <mtjjma$p7f$1_at_dont-email.me>


On 09/19/2015 10:26 AM, Luuk wrote:
[...]
>
> SELECT DISTINCT has_communicated_with_A FROM (
> SELECT DISTINCT `to` AS 'has_communicated_with_A' FROM table WHERE
> `from` = 'A'
> UNION ALL
> SELECT DISTINCT `from` FROM table WHERE `to` = 'A'
> )
>

You can simplify that a bit:

SELECT `to` AS has_communicated_with_A FROM table WHERE `from` = 'A' UNION
SELECT `from` FROM table WHERE `to` = 'A'

UNION alone will remove duplicates so there is no need for DISTINCT in the sub-query and since the result of the UNION is already unique, there is no need for the outer SELECT.

[...] Received on Sat Sep 19 2015 - 14:18:05 CEST

Original text of this message