指令条件是否检查双记录

时间:2016-07-25 16:43:40

标签: 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'
}

1 个答案:

答案 0 :(得分:0)

有几种选择。这是使用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)