开发者

How can I exclude a certain row from an MySQL query

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 sim开发者_开发技巧ilar 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.


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.


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 =)


SELECT * FROM imdb WHERE genres LIKE 'Adventure' and id != 1 ORDER BY id DESC LIMIT 10


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";
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜