我试图使用select
语句来获取某个MySQL表中的所有行,除了在user_id为5,6,7的三个中。下面是代码,但它无法正常工作。请帮忙。
$sql = "SELECT * FROM login ORDER BY user_id ASC LIMIT 0, 20 WHERE user_id<>5,6,7";
答案 0 :(得分:3)
您必须对多个ID使用 NOT IN 功能。
$sql = "SELECT * FROM login WHERE user_id NOT IN (5,6,7) ORDER BY user_id ASC LIMIT 0, 20"
答案 1 :(得分:2)
$sql = "SELECT * FROM login WHERE user_id<>5 ORDER BY user_id ASC LIMIT 0, 20 "
查看Order by,Where Clause和Order of operations
正如您刚刚更改了您的问题,新答案是
$sql = "SELECT * FROM login WHERE user_id NOT IN (5,6,7) ORDER BY user_id ASC LIMIT 0, 20 "
查看NOT IN
答案 2 :(得分:2)
这样做:
SELECT * FROM login WHERE NOT user_id = 5, ORDER BY user_id ASC LIMIT 0, 20
答案 3 :(得分:-1)
试试这个:
$sql = "SELECT * FROM `login` WHERE `user_id` NOT IN (5,6,7) ORDER BY `user_id` ASC LIMIT 0, 20";