Monday, 15 August 2011

mysql - Select multiple columns from one alias -



mysql - Select multiple columns from one alias -

in schema, there 2 tables same column names (changing them not option)

performing query select * taba bring together tabb results in mysql error of 'duplicate column name col'

the solution select using aliases, not want type alias.col every column (since need columns both tables)

is possible along lines of:

select taba.(cola, colb, colc...), tabb.(cola, colb, colc...)

no not possible.

you have that

select taba.cola, taba.colb, taba.colc..., tabb.cola, tabb.colb, tabb.colc...

if have same name column in both tables , give other alias that.

lets have id column name in both tables.

select taba.id , tabb.id id_b

will give result

id id_b

linger's fiddle

mysql join aliases

No comments:

Post a Comment