php - MySQL 基础问题 : how to get rows from one table that are not in another table?

标签 php mysql

我的“用户”表中有一个用户名列表(带有一个名为“用户名”的列)+ 其他信息。

我的较小的“recentusers”表中还有另一个用户名列表(带有一个名为“用户名”的列)。

我如何创建一个 mysql 查询来获取“users”表中但不在“recentusers”表中的所有用户名?

我知道这可能非常简单,但我们将不胜感激!

最佳答案

select username from users where username not in (select username from recentusers)

然后在第一个用户名之后添加您要选择的其他信息。

正如 OMG Ponies 所指出的,此查询的运行速度与使用 Left Join or Is null. 一样快

关于php - MySQL 基础问题 : how to get rows from one table that are not in another table?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1785799/

相关文章:

MYSQL数据导入更改时间

mysql - debian linux 升级 mysql - 查找差异后继续

javascript - AJAX 请求、表单提交中出现解析器错误

mysql - 使用 MySQL 获取用户排名

php - 将自定义 (PHP) 日历与 iCal/Google 日历同步?

javascript - 在 AngularJS 中重新加载 php 页面

mysql - 如何将子查询写成 not null as join

python - 使用 Peewee 选择一列

PHP MYSQL 列数据下拉列表

php - 如何将选择选项(产品属性)转换为 WooCommerce 可变产品页面中的可点击 div?