Reputation: 4166
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
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