sql - Why MySQL union all shows different result for "practically" the same query? -


i making query , i'm wrong results, modified , works, query similar original, it:

original: (didn't work)

select username, password tbl_user union select username password, password username tbl_user 

results:

user1 | pass1 userunion1 | passunion1 

solution: (working)

select username, password tbl_user union select password username , username password tbl_user 

results:

user1 | pass1 passunion1 | userunion1 

the intension of query union same result columns inverted, in original query doesn't invert columns, in solution query ¿why?

(note in original query i'm ordering asume password username , username password), can explain?

in first query:

select username, password tbl_user union select username password, password username tbl_user 

you taking union of tbl_user itself. aliases in second half of union ignored. query identical doing:

select username, password tbl_user union select username, password tbl_user 

similarly, working second query identical to:

select username, password tbl_user union select password, username tbl_user 

the general rule of thumb union queries in mysql , databases types and number of columns same in each select list.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -