John
John

Reputation: 7880

php / mysql - select id from one table excepting ids which are in another table

for example i have 2 tables:
1 . users:

id     Name
1       Mike
2       Adam
3       Tom
4       John
5       Andy
6       Ray

2 . visits:
userID     date
1           ...
3           ...
6           ...

i want to make a page which can be visited once in 12 hours, when user visits that page his id is included in database ( visits ), how i can select all users ( from database users) excepting users who visited page in <= 12 hours ( users from database visits )?

Upvotes: 2

Views: 929

Answers (1)

Stefan H Singer
Stefan H Singer

Reputation: 5504

First of all, you don't mean "from one database [...] which are in second database", they're just in different tables, but in the same database :)

Anywho, something like this:

SELECT * FROM users WHERE id NOT IN 
(SELECT userID FROM visits WHERE date > DATE_SUB(NOW(), INTERVAL 12 HOUR)) 

or something like that :)

Upvotes: 1

Related Questions