I have a list of feeds:
('feed1', 'feed2', 'feed3')
I also have a table feeds
with a list of feeds, I need to find which feeds in my search list don't appear in the database.
CREATE TABLE `feeds_filte开发者_运维问答red` (
`id` CHAR(36) NOT NULL,
`url` VARCHAR(255) NOT NULL,
......
PRIMARY KEY (`id`)
) ENGINE=MYISAM DEFAULT CHARSET=utf8;
For example feed1 and feed3 exist in my table so I want feed 2 returned. Please note: that the feeds table also has feed4, feed5 etc so I don't want them returned either. Only feed2
I can easily write a PHP script to do this, but I was wondering if there was an easy way to do this is MySQL?
Thanks in adavnce!
You could create a temporary table, do a LEFT JOIN
, then get the records where the RHS of the join is NULL
.
You can select the items from one table that don't appear on another table, ie:
select * from feeds_filtered where url not in (select url from feeds)
You can use a query like:
select * from feeds_filtered
where url is not in ('feed1', 'feed3')
精彩评论