如何从 MySQL 查询中排除特定行

发布于 2024-12-02 19:47:49 字数 244 浏览 1 评论 0原文

我想从 MYSQL 查询中排除特定行。

SELECT * FROM imdb WHERE genres LIKE 'Adventure' ORDER BY id DESC LIMIT 10

这是一个电影网站,所以我检索了类似的冒险电影,但这包括当前的电影。

所以我需要这样的东西:

选择像 Adventures 这样的电影,但排除这个 id:1,但是,结果是 10 部电影。

I want to exclude a certain row from an MYSQL query.

SELECT * FROM imdb WHERE genres LIKE 'Adventure' ORDER BY id DESC LIMIT 10

It's for a movie website, so I retrive similar Adventures movie, but this includes the current movie.

So I need something like this:

Select the movies like Adventures, but exclude this id: 1, yet, results 10 movies.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

逆蝶 2024-12-09 19:47:49

如果您知道确切的 id(例如 id = 1),请执行以下操作:

SELECT * FROM imdb WHERE genres LIKE 'Adventure' AND id <> 1 ORDER BY id DESC LIMIT 10

请参阅此 SO 帖子

If you know the exact id (say, id = 1 for example), do this:

SELECT * FROM imdb WHERE genres LIKE 'Adventure' AND id <> 1 ORDER BY id DESC LIMIT 10

See this SO post.

与之呼应 2024-12-09 19:47:49

也许是这样的?

SELECT * 
FROM imdb 
WHERE genres LIKE 'Adventure' AND
  ID NOT IN (1)
ORDER BY id DESC LIMIT 10

您可以将不想包含的 ID 列表放在 NOT IN 后面的括号之间。

编辑:如果您知道要排除的特定 ID 组,您也可以在这些括号之间放置查询:

WHERE genres LIKE 'Adventure' AND
  ID NOT IN (SELECT ID FROM imdb WHERE LeadActor='Pauly Shore') --You know you want to exclude him =)

Something like this maybe?

SELECT * 
FROM imdb 
WHERE genres LIKE 'Adventure' AND
  ID NOT IN (1)
ORDER BY id DESC LIMIT 10

You can put a list of IDs you don't want to include between the parenthesis after NOT IN.

EDIT: You could also put a query in between those parens if you know a particular group of ID's you want to exclude:

WHERE genres LIKE 'Adventure' AND
  ID NOT IN (SELECT ID FROM imdb WHERE LeadActor='Pauly Shore') --You know you want to exclude him =)
浸婚纱 2024-12-09 19:47:49
SELECT * FROM imdb WHERE genres LIKE 'Adventure' and id != 1 ORDER BY id DESC LIMIT 10
SELECT * FROM imdb WHERE genres LIKE 'Adventure' and id != 1 ORDER BY id DESC LIMIT 10
摘星┃星的人 2024-12-09 19:47:49

为了不显示当前用户数据,以下是查询

$sql = "SELECT u1.parent_id, m1.meta_value AS headline
        FROM wp_vandor u1
        JOIN wp_usermeta m1 ON (m1.user_id = u1.child_id AND m1.meta_key = 'headline') 
        WHERE m1.user_id!=$currentuser_id";

For not showing current user data, below is the query

$sql = "SELECT u1.parent_id, m1.meta_value AS headline
        FROM wp_vandor u1
        JOIN wp_usermeta m1 ON (m1.user_id = u1.child_id AND m1.meta_key = 'headline') 
        WHERE m1.user_id!=$currentuser_id";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文