我的mysql中的一个表有1000多条数据,搜索却只能看到500多条,急!
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了我的mysql中的一个表有1000多条数据,搜索却只能看到500多条,急!相关的知识,希望对你有一定的参考价值。
比如运行:SELECT * FROM members WHERE ID=1000能查出来
但运行:SELECT * FROM members却只有500多个数据
这些数据里包括中文,猜想可能是这里出问题了
select count(*) from members;结果是1337
但select * from members;出来只有500多条
mysql左联查询时 右表有多条关联左表同一记录的信息,只要有右表中有条件不符合,就不显示该所有左表记录
左表
CREATE TABLE `roominfo` (
`roomID` int(11) NOT NULL AUTO_INCREMENT,
`roomNum` int(11) NOT NULL,
`classID` int(11) NOT NULL,
`available` tinyint(1) NOT NULL DEFAULT '1',
`used` tinyint(1) NOT NULL DEFAULT '0',
`booked` tinyint(1) NOT NULL,
`mark` varchar(50) DEFAULT NULL,
PRIMARY KEY (`roomID`),
KEY `classID` (`classID`),
KEY `roomNum` (`roomNum`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=latin1;
-- ----------------------------
-- Records of roominfo
-- ----------------------------
INSERT INTO `roominfo` VALUES ('1', '1', '1', '1', '0', '0', 'null');
INSERT INTO `roominfo` VALUES ('2', '2', '2', '1', '0', '0', 'mark');
INSERT INTO `roominfo` VALUES ('11', '101', '1', '1', '0', '1', 'mark');
INSERT INTO `roominfo` VALUES ('12', '102', '1', '1', '0', '0', '');
INSERT INTO `roominfo` VALUES ('13', '103', '2', '1', '0', '0', 'null');
INSERT INTO `roominfo` VALUES ('14', '104', '2', '1', '0', '0', '');
右表:
CREATE TABLE `orders` (
`orderID` int(11) NOT NULL AUTO_INCREMENT,
`userNickName` varchar(30) NOT NULL,
`roomNum` int(11) NOT NULL,
`bookInDate` date NOT NULL,
`bookOutDate` date NOT NULL,
`mark` varchar(255) DEFAULT NULL,
PRIMARY KEY (`orderID`),
KEY `userNickName` (`userNickName`),
KEY `roomNum` (`roomNum`),
CONSTRAINT `orders_ibfk_1` FOREIGN KEY (`userNickName`) REFERENCES `customerinfo` (`nickName`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
-- ----------------------------
-- Records of orders
-- ----------------------------
INSERT INTO `orders` VALUES ('1', 'aa', '101', '2013-12-24', '2013-12-26', null);
INSERT INTO `orders` VALUES ('2', 'lee', '101', '2013-12-20', '2013-12-21', null);
查询:
SELECT
roominfo.roomNum,
roominfo.classID
FROM
roominfo
LEFT OUTER JOIN orders ON orders.roomNum = roominfo.roomNum
where roomInfo.available = 1 and roomInfo.used = 0 and (booked = 0 or
(orders.bookInDate > '2013-12-22' and orders.bookInDate > '2013-12-25') OR (orders.bookOutDate < '2013-12-22' and orders.bookOutDate < '2013-12-25'))
只要 时间有一条不符合,那么所有关于roomNum 101 的记录都不显示,
谢谢
roominfo.roomNum,
roominfo.classID
FROM
roominfo
LEFT OUTER JOIN orders ON orders.roomNum = roominfo.roomNum
where roomInfo.available = 1 and roomInfo.used = 0 and (booked = 0 or
(orders.bookInDate > '2013-12-22' and orders.bookInDate > '2013-12-25') AND (orders.bookOutDate < '2013-12-22' and orders.bookOutDate < '2013-12-25'))
以上是关于我的mysql中的一个表有1000多条数据,搜索却只能看到500多条,急!的主要内容,如果未能解决你的问题,请参考以下文章