Writing UNION statements in MySQL 3.x
(Page 1 of 4 )
For those of us who use MySQL, I think we can all share in our annoyance at the lack of the UNION command. We've been told that it will be implemented in the version 4.0 release, but we've been waiting a long time, and I doubt this will be resolved anytime soon. So, I guess that means we have to find our own way around the UNION statement.
By : Michael Bailey
For those of us who use MySQL, I think we can all share in our annoyance at the lack of the UNION command. We've been told that it will be implemented in the version 4.0 release, but we've been waiting a long time, and I doubt this will be resolved anytime soon. So, I guess that means we have to find our own way around the UNION statement.
For those of you who do not know, the UNION statement allows a query to combine more than one SELECT statement into one all-powerful result set. This is useful when you have two tables with similar fields which you wish to combine into one SELECT. An example of this would be payments and charges in an accounting database. Each would be in a separate table, but each has similar fields (ex. amount, date, description, account, etc...).
Without the UNION, you have to make two queries and combine them on the client side. This can be laborious in many situations, especially those which require sorting. As a rule of thumb, it's always best to let SQL do as much of the processing as possible. It saves in transfer time and processor time.
So, how can one use a UNION statement without "using" a UNION statement?
Next: Overview >>
More Database Articles Articles
More By Codewalkers