How to write a query with DISTINCT or GROUP BY?

there is such a request
(SELECT * FROM notification_role WHERE notification_role.role="curator") UNION (SELECT * FROM notification_user WHERE notification_user.user_id=15)

badcce3c4824425798830ac6141f37d6.png
Question: how to combine 2 query trigger on the field to have only unique values
July 9th 19 at 13:25
1 answer
July 9th 19 at 13:27
Solution
SELECT DISTINCT [trigger] FROM notification_role WHERE notification_role.role="curator"
UNION 
SELECT DISTINCT [trigger] FROM notification_user WHERE notification_user.user_id=15

UNION and so collects only unique attributes.
UNION ALL — all.
is not suitable, then we choose distinct TO union, it's useless, because the tables initially may not be the same, but AFTER the union we receive a duplicate, here it is necessary to have only unique - Diamond.Hartma commented on July 9th 19 at 13:30
: "initially may not be the same," get DISTINCT - Arlo.OReill commented on July 9th 19 at 13:33
: "appears to duplicate" because only need to use the field that requires uniqueness, but not all. And UNION will be given only do not duplicate attribute names. - Arlo.OReill commented on July 9th 19 at 13:36
really, what you need)
rewrote
(SELECT `trigger` FROM notification_role WHERE notification_role.role="curator") UNION (SELECT `trigger` FROM notification_user WHERE notification_user.user_id=15)
and now only displays unique values trigger. Thank you) - Diamond.Hartma commented on July 9th 19 at 13:39

Find more questions by tags MySQLSQL