[SOLVED] Union query giving unexpected results

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

[SOLVED] Union query giving unexpected results

Post by impulse() »

I've been asked to modify a script which has a union query to fetch data from 2 different tables. Both tables have different amount of columns with different names but essentially they store the same data. At the moment the query includes something like:

"SELECT something AS otherTablesColumnName"

so the union query works OK and it does work OK. But I'm being asked to include as column from table 1 which isn't in table 2. I've tried to trick MySQL into doing this by adding an extra column to table 2 named 'notused' then including:

'SELECT notused AS columnIWantFromTable1"

And this kind of works because it fetches the first character from the field in table 1 but nothing else. Could somebody explain why this happens please?

If you need more information I will be checking this thread regularly throughout the day.
Last edited by impulse() on Tue Dec 11, 2007 4:14 am, edited 1 time in total.
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

Solved now.

I'd only put a varchar(1) column in the table without the extra field which was setting the column type and length.
Post Reply