表的结构大概是这样的
id gid
1 2
2 2
3 3
4 3
5 4
6 5
7 6
8 1
9 2
10 3id为自增主键 gid为另一个表中的id现在我通过前期处理,得到了 `gid` IN (2,3,4)
这样的一个条件
所以 我的sql语句是这么写的$sql="SELECT * FROM `tablename` WHERE `gid` IN (2,3,4) ORDER BY `id` DESC LIMIT 0,16";但是很奇怪!只能求出 id为1,3,5的3条数据
即:gid重复的数据 没有求到请问 正确的mysql语句要如何书写!?多谢了
id gid
1 2
2 2
3 3
4 3
5 4
6 5
7 6
8 1
9 2
10 3id为自增主键 gid为另一个表中的id现在我通过前期处理,得到了 `gid` IN (2,3,4)
这样的一个条件
所以 我的sql语句是这么写的$sql="SELECT * FROM `tablename` WHERE `gid` IN (2,3,4) ORDER BY `id` DESC LIMIT 0,16";但是很奇怪!只能求出 id为1,3,5的3条数据
即:gid重复的数据 没有求到请问 正确的mysql语句要如何书写!?多谢了
`id` int(20) NOT NULL auto_increment,
`name` varchar(255) collate utf8_unicode_ci default NULL,
`filename` varchar(255) collate utf8_unicode_ci default NULL,
`code` text collate utf8_unicode_ci,
`content` text collate utf8_unicode_ci,
`gid` int(20) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=8 ;
mysql> insert game_vedio (gid) values (2),(2),(3),(3),(4),(5),(6),(1),(2),(3);
Query OK, 10 rows affected (0.00 sec)
Records: 10 Duplicates: 0 Warnings: 0mysql> SELECT * FROM `game_vedio` WHERE `gid` IN (2,3,4) ORDER BY `id` DESC LIMIT 0,16;
+----+------+----------+------+---------+------+
| id | name | filename | code | content | gid |
+----+------+----------+------+---------+------+
| 10 | NULL | NULL | NULL | NULL | 3 |
| 9 | NULL | NULL | NULL | NULL | 2 |
| 5 | NULL | NULL | NULL | NULL | 4 |
| 4 | NULL | NULL | NULL | NULL | 3 |
| 3 | NULL | NULL | NULL | NULL | 3 |
| 2 | NULL | NULL | NULL | NULL | 2 |
| 1 | NULL | NULL | NULL | NULL | 2 |
+----+------+----------+------+---------+------+
7 rows in set (0.00 sec)
楼主试试查其中一种情况,看看数据是什么样的
SELECT * FROM `tablename` WHERE `gid` =2 ORDER BY `id` DESC LIMIT 0,16
已经找到问题了 不是sql语句的问题多谢楼上诸位