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

From: Date: Fri, 14 Jan 2005 16:54:24 +0000
Subject: Re: [suspicious - maybe spam] [PHP] [suspicious - maybe spam] strange in MySQL Query.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-206388@lists.php.net to get a copy of this message
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

« previous php.general (#206388) next »