Reply to Re: [suspicious - maybe spam] [PHP] [suspicious - maybe spam] strange in MySQL Query.

Your name:

Reply:


Posted by Richard Lynch on 01/14/05 18:54

adwin wijaya wrote:
> SELECT "group" as type FROM mytable WHERE id ="101010"
> UNION
> SELECT "individual" as type FROM myothertable WHERE id="101010"
>
> The strange result if only one result displayed from myothertable, so
> the "type" will become "indiv" instead of individual.
>
> But when I tried to switch the query become :
>
> SELECT "individual" as type FROM myothertable WHERE id="101010"
> UNION
> SELECT "group" as type FROM mytable WHERE id ="101010"
>
> it could displaye the result correctly. I dont know why .. is this mysql
> bug ?

Where's the PHP part?

The data type of your return columns MUST MATCH in a UNION.

The data type of "group" would be... char(5) since it has no inherent
data type.

So when you put "group" first, MySQL uses char(5)

When you put "individual" first, MySQL uses char(10)

You can play with this some more with longer/short strings to verify.

If you force the type of 'group' to be, say, varchar(255) the discrepency
will disappear.

--
Like Music?
http://l-i-e.com/artists.htm

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация