php - if 检查双重记录的条件指令

标签 php mysql

我有这张表:enter image description here

如何编写指令 if ,它将检查同时存储的记录(在我的表中是列 created_at )。 例如:

if(created_at for record where key(it's column)='stan' it is the same as created_at for key='stan_key' {
    return records where key='stan'
}

最佳答案

有几个选项。这是使用 exists 的版本:

select * 
from yourtable y1
where y1.key = 'stan' and exists (
    select 1
    from yourtable y2
    where y2.key = 'stan_key' and y1.created_at = y2.created_at)

关于php - if 检查双重记录的条件指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38573303/

相关文章:

PHP MYSQL 使用 JSON 提供的内容构建动态 UPDATE 查询

php - 生成表中的列总和

MySQL - 从表的 id 字段中没有对应项的数字列表中选择

php - 如何在单个函数中执行两个表列数据

php - MySQL 与 php 类的连接

php - PHP\MySQL 查询中的 JavaScript

php - 访问类常量槽属性不起作用

mysql - 合并两个表数据的查询

mysql - 如何永久禁用 MySQL 8 中的列统计信息?

PHP MYSQL unserialize() 问题