开发者

MySQL selecting distinct names from two columns

开发者 https://www.devze.com 2022-12-20 06:51 出处:网络
I have two columns of coaches names: coach1 JOHN JACOB MARY coach2 JOHN JAC开发者_运维问答OB HENRY I would like to select all DISTINCT values between the two columns.

I have two columns of coaches names:

coach1
JOHN
JACOB
MARY

coach2
JOHN
JAC开发者_运维问答OB
HENRY

I would like to select all DISTINCT values between the two columns.

So that my SELECT statement will read,

JOHN
JACOB
MARY
HENRY

with no duplicates. Any suggestions as to the most efficient way to do this?


SELECT COACH1 AS NAME FROM TABLE
UNION
SELECT COACH2 AS NAME FROM TABLE

Is a way to do. I'm not saying it's the "most" efficient to do, though :) Shouldn't be too bad. UNION by default will select only distinct values.

0

精彩评论

暂无评论...
验证码 换一张
取 消