php - MySQL - Rename selected columns with the same name from two different tables -
i'm selecting same column 2 different tables, want utilize select as
create them different names.
(select letter letter_1, sex sex_1 `celebs_a` limit 1) union (select letter letter_2, sex sex_2 `celebs_b` limit 1)
that query returns this:
letter_1 sex_1 1 b 1
but, want homecoming this:
letter_1 letter_2 sex_1 sex_2 b 1 1
how can create query homecoming each value different column name? thanks.
select max(letter_1) letter_1, max(sex_1) sex_1, max(letter_2) letter_2, max(sex_2) sex_2 ( (select letter letter_1, '' letter_2, sex sex_1, 0 sex_2 celebs_a limit 1) union (select '' letter_1, letter letter_2, 0 sex_1, sex sex_2 celebs_b limit 1) ) derived_table_must_have_an_alias
you can extend selecting multiple columns each table. set 0
or ''
placeholder columns in other table.
php mysql
No comments:
Post a Comment