简体   繁体   English

PHP / MySQL的-从一个表中选择ID,除了在另一个表中的ID

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

for example i have 2 tables: 例如我有2表:
1 . 1。 users : 用户

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

2 . 2。 visits : 访问次数
\nuserID date 用户ID日期\n1 ... 1 ...\n3 ... 3 ...\n6 ... 6 ...\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 users ) excepting users who visited page in <= 12 hours ( users from database visits )? 我想制作一个可以在12小时内访问一次的页面,当用户访问该页面时,他的ID已包含在数据库中(访问),我如何选择所有用户(从数据库用户中 ),但访问<= 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 :) 或类似的东西 :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PHP MySQL从一个表中选择ID,从另一个表中选择信息 - PHP MySQL Select ID from one table and information from another table MySQL SELECT COUNT从一个表和ID从另一个表? - MySQL SELECT COUNT from one table and ID from another? PHP 代码将 SELECT 来自一个 MySQL 表,但不是来自另一个 - PHP code will SELECT from one MySQL table but not from another PHP-SQL如何从表中选择ID并插入到另一个表中? - PHP - SQL how to select ids from table and insert into another table? 在MySQL php中将ID从一个表插入另一个表 - Insert ID from one table to another in MySQL php MySQL PHP ID在一个表中而不是另一个表中 - MySQL PHP ID in one table and not another 从一个表中选择行,其中基于第二个表ID的另一个第二个表中的ID显示结果的顶部以及下一个结果,因为它是+ Mysql - Select rows from a table where id in another second table based on second table ids shows results top as well as next results as it is + Mysql 从一个MySQL表的两行获取ID,然后使用PHP在另一个MySQL表的一行中输入这些值 - Taking ids from two rows of one MySQL table and entering those values in one row of another MySQL table using PHP 如何根据mySQL中另一个表的ID省略选择结果? - How to omit select results based on IDs from another table in mySQL? mysql-通过id从一个表中选择一个产品,然后从另一个表中选择其关联的图像 - mysql- select a product from one table by id, then its associated images from another table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM