MySQL Forums
Forum List  »  Newbie

Re: any alternatives for achieving "UNION " of multiple tables??
Posted by: Roland Bouman
Date: August 08, 2005 12:55PM

missterie wrote:
> union statement to display all columns found for a
> particular ID is my desire. E.g
>
> select t1, t2 from table1 where ID=12 union select
> t1, t2 from table2 where ID=12

This select column t1 and column t2. Are these all columns? Or do you mean you want to select all *rows*? THe reason I ask this, is that the statement should always return a set with two columns, even if it is an empty set.
If you actually mean rows (and not columns) it could be due to the fact that you are using UNION, not UNION ALL (UNION will mege duplicate rows into a single one, UNION ALL preserves duplicates)

> tag as I want it to. I only get one column even
> though am selecting multiple columns. Maybe due to

And what happens if you do just

select t1, t2 from table1 where ID=12

do you get one column or two columns?
Are sure you have a comma between t1 and t2. Ommitting that is a fairly common error and it has the effect of renaming (aliasing) the first column to the name of the first:

select t1 t2 is similar to select t1 as t2

> time left to do so. So mySQL question is,
> Is there an alternative way to achieving the union
> of multiple tables?

I do not think that this in particular is possible.

Options: ReplyQuote


Subject
Written By
Posted
Re: any alternatives for achieving "UNION " of multiple tables??
August 08, 2005 12:55PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.