开发者

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 whi开发者_JAVA百科ch 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 )?


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 :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜