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.
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";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.