开发者

My SIGNED INT is casted to UNSIGNED when I do a LEFT JOIN

I'm trying to SUM() with UNSIGNED INT in MySQL. When I join another table, the SIGNED INT becomes an UNSIGNED INT.

SELECT `weight` FROM `article_vote`
 LEFT JOIN `vote` ON `vote`.`id` = `article_vote`.`article_id`

returns:

1
1
1
1
1
1
1
1
1
1
1

However, SELECT weight FROM vote returns:

1
1
1
1
-1
1
1
-1
-1
-1
1

Any ideas?

--

EDIT

Those 11 rows are the total records in the table, so there are not any ORDER or LIMIT.


EDIT

TABLE CREATE:

CREATE TABLE `vote` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) DEFAULT NULL,
  `weight` int(11) NOT NULL,
  `resource_type` varchar(255) NOT NULL,
  `submited_date` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `IDX_5A108564A76ED395` (`user_id`),
  CONSTRAINT `vote_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8;

CREATE TABLE `article_vote` (
  `id` int(11) NOT NULL,
  `article_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `IDX_8F6C754A62922701` (`anecdote_id`),
  CONSTRAINT `article_vote_ibfk_1` FOREIGN KEY (`article_id`) REFERENCES `article` (`id`),
  CONSTRAINT `article_vote_ibfk_2` FOREIGN KEY (`id`) REFERENCES `vote` (`id`) 开发者_开发知识库ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


Perhaps the negative weights are being reordered to come later in the result set (after the LIMIT clause that the standard MySQL client applies by default).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜