Professional Web Applications Themes

UNION query - MySQL

Hello- I am working on a small web project, and I have 3 queries that look like this: select * from table1; select * from table2; select * from table3; table1 had 3 columns, table2 has 4 columns, and table3 has 5 columns. Unfortunately, due to poor design I can not at this time change the query syntax of these;however, I would like to add a UNION statement to them. Again, poor design dictates that the UNION statement be the same for each of these queries. Of course the problem is the number of columns is different. Is there any ...

  1. #1

    Default UNION query

    Hello-

    I am working on a small web project, and I have 3 queries that look like
    this:

    select * from table1;
    select * from table2;
    select * from table3;

    table1 had 3 columns, table2 has 4 columns, and table3 has 5 columns.

    Unfortunately, due to poor design I can not at this time change the query
    syntax of these;however, I would like to add a UNION statement to them.
    Again, poor design dictates that the UNION statement be the same for each of
    these queries.

    Of course the problem is the number of columns is different. Is there any
    possible way I can use an ISNULL or something similar to determine the
    number of columns returned by my UNION statement? I am only concerned with
    the data UNION'd in the 1st column, and am just returning 0's for the rest,
    like:

    UNION name,0,0

    If I could dynamically add columns with values of 0 within the SQL, that
    would work.

    Like I said, this is poor design (it is *not* mine!) but I can't change
    these things at this time - but I am working towards it!

    Thanks
    John


    John Guest

  2. #2

    Default Re: UNION query

    "John Raines" <com> wrote in message
    news:net... 

    Would it be possible to replace the mismatch fields with placeholder
    variables to satisfy the UNION statement?


    Bosconian Guest

  3. #3

    Default Re: UNION query


    "Bosconian" <com> wrote in message
    news:com... 
    >
    > Would it be possible to replace the mismatch fields with placeholder
    > variables to satisfy the UNION statement?
    >[/ref]


    Do you mean in the original SQL query? As of right now I am unable to modify
    it, which really s I know, but I have no choice at the moment.



    John Guest

  4. #4

    Default Re: UNION query

    "John Raines" <com> wrote in message
    news:net... 
    >>
    >> Would it be possible to replace the mismatch fields with placeholder
    >> variables to satisfy the UNION statement?
    >>[/ref]
    >
    >
    > Do you mean in the original SQL query? As of right now I am unable to
    > modify it, which really s I know, but I have no choice at the moment.
    >
    >
    >[/ref]

    Oh, I thought you could change the query, but not the database schema.

    In that case the only thing you can do is merge the data at the code level.
    That's a pain, but doable.


    Bosconian Guest

Similar Threads

  1. #39270 [NEW]: mysql_field_table() Doesnt Work With UNION Query
    By jkeller at fieldtechnologies dot com in forum PHP Bugs
    Replies: 1
    Last Post: October 26th, 08:51 PM
  2. Getting recordcount from resultset of 'union' query
    By Marja Ribbers in forum Dreamweaver AppDev
    Replies: 3
    Last Post: May 7th, 07:05 PM
  3. ORDER BY in UNION query
    By Antony Paul in forum PostgreSQL / PGSQL
    Replies: 4
    Last Post: January 17th, 11:59 AM
  4. Sorting With a UNION Query?
    By MDW in forum ASP Database
    Replies: 2
    Last Post: June 10th, 03:25 PM
  5. UNION QUERY
    By Christopher Harvey in forum PHP Development
    Replies: 1
    Last Post: September 7th, 10:50 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139