List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:August 29 2002 4:43am
Subject:Re: Join with Union
View as plain text  
At 12:02 +0900 8/29/02, suresh wrote:
>I changed from mysql  3.23.49 -nt to 4.0.2 max to make use of union
>But one problem  when trying to join  tables is that UNION works 
>only for SELECT queries with same number of coulmns.

Well, that's how UNION works.

>  Is there any way to join 3 or more tables having different columns 
>using UNION?

Sure, you can use different columns.  But you have to have the same
*number* of columns.

>  I am writing my query during the runtime. Since the user can select 
>any number of fileds from a particular table and also I am using 
>LEFT JOIN, I can't make all the tables having same number of fields.

Sure you can.  Add fake columns that select some constant value, like
an empty string, 0, or NULL.  Pad the "short" tables with enough of these
so that you select the same number of columns from each.

If you don't have any way to tell how many columns are selected, then
you're stuck.  But I find it hard to conceive of such a situation.

>Thanks for any help

Join with Unionsuresh29 Aug
  • Re: Join with UnionDan Nelson29 Aug
  • Re: Join with UnionPaul DuBois29 Aug
Re: Join with UnionDan Nelson29 Aug