Reputation: 559
I want to get date from database where the logout date is smaller than status posted date.
My current query which is running is as follows :
SELECT user.logout, status.date
From user
Inner join status
ON user.uid=status.uid;
This can get the date for both logout date and posted date, but the problem is how to compare the dates. I'm using timestamp to store the date, so the format will be same,
I have tried something like this :
SELECT if user.logout < status.date
From user
Inner join status
ON user.uid=status.uid where date(user.logout) < date(status.date)
but it doesn't work. Please help me with this.
Thanks in Advance
Upvotes: 1
Views: 121
Reputation: 59
You should try something like this, as instead of comparing in select part, you should do it in where clause.
SELECT user.logout, status.date
FROM user
INNER JOIN status ON user.uid=status.uid
WHERE user.logout < status.date
Upvotes: 2
Reputation: 831
if date's are in time stamp then use date()
keyword..
SELECT
USER .logout,
STATUS .date
FROM USER
INNER JOIN STATUS ON USER .uid = STATUS .uid
WHERE date(USER .logout) < date(STATUS .date)
Upvotes: 0