简体   繁体   中英

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

for example i have 2 tables:
1 . :


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

2 . :
\n \n1 ... \n3 ... \n6 ... \n

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 ) excepting users who visited page in <= 12 hours ( users from database )? ),但访问<= 12的除外小时(来自数据库用户)?

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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM