W
W
WebDev2015-11-01 00:30:28
MySQL
WebDev, 2015-11-01 00:30:28

What is the best way to filter data?

There is a news feed, new ones are added every day. A person comes in and reads, we save the news he read to the database.
Question: how, in this case, is it more efficient and more correct to filter the news by "read / not read". Now each read news is recorded in the database, and the unread ones are selected like this:

select * from news where id not in (select id from viewed)

There is a lot of news, there are also a lot of viewed news. Is this approach bad or is everything ok? Base on MySQL.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Martyanov, 2015-11-01
@vilgeforce

UPDATE TABLE usersSettings SET lastViewed=NOW() WHERE userID = ...;
SELECT * FROM news WHERE newsTime > (SELECT lastViewed FROM usersSettings WHERE userID = ...) ;
Maybe something like this.

I
Immortal_pony, 2015-11-01
@Immortal_pony

"a lot" is how much? If we are not talking about millions, then it will go.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question