How can I exclude a certain row from an MySQL query
18,359
Solution 1
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.
Solution 2
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 =)
Solution 3
SELECT * FROM imdb WHERE genres LIKE 'Adventure' and id != 1 ORDER BY id DESC LIMIT 10
Author by
Special K.
Updated on July 25, 2022Comments
-
Special K. almost 2 years
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.
-
Special K. almost 13 yearsThank you, it did work, and actually I did this before, but visually in the MySQL results show me the id I wanted to exclude too, but the text was Showing rows 0 - 3 (4 total, Query took 0.0012 sec) [id: 243 - 229], so thank you again for brining the light.
-
Josh Darnell almost 13 years@Wtstatscom: By the way, you can click the empty "Check Mark" symbol next to JW's answer to indicate that it worked for you =)
-
Josh Darnell almost 13 years@Wtstatscom: There is a screenshot here. =)
-
Special K. almost 13 years@jadarnel27 - Thank you & done, thank you guys. You were so fast with the replies.