Jeremy@thebunnyshed.co.uk wrote:
> After spending the last hour tracking down a problem with my large
> query, I have isolated this simple test case:
>
> SELECT 1 AS Test1, 2 As Test2
> UNION ALL
> SELECT 2 As Test2, 1 AS Test1
>
> Produces:
>
> Test1 Test2
> 1 2
> 2 1
>
> This looks very obviously wrong to me, but just wanted to check it's
> not me misunderstanding some kind of usage rules with UNION or
> something.
>
> Cheers,
> Jeremy
>
That is correct. You are retrieving two columns - A and B, in that
order. And that is how both rows are displayed.
MySQL command line does show the names at the top of the column for your
convenience, and when using a UNION, those names come from the first
clause. But MySQL does not resequence the columns based on the names.
Those are there only for your convenience.
In a program, if you return the elements in an indexed (non-associative)
array, you will get as shown. But you retrieve them as an associative
array, [Test1] will contain 1 in both rows and [Test2] will contain 2 in
both rows.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================