Ted
Ted

Reputation: 4166

MySQL: compare two columns against single condition

Is there any way to compare single condition against two columns (datetime)

sample of current SQL query:

select *
from user u
inner join user_info ui on ui.user_id = u.id
where u.create_date > '2015-10-01'
and ui.create_date > '2015-10-01'

is there a way to validate "date" by posting it only once in the query?

Upvotes: 1

Views: 170

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269653

There are several ways. Here is one:

select *
from user u inner join
     user_info ui
     on ui.user_id = u.id
where least(u.create_date, ui.create_date) > '2015-10-01';

Upvotes: 4

Related Questions