mysql - Sql query that selects all inactive users -


i have query implement.

i have 2 tables: user , login_logs table.

the user table looks this:

id || first_name || last_name ||           email                 || username || activated || suspended

1 ||       john       ||      dan       ||      john@whatever       ||      john1    ||     1      ||       0       ||

2 ||       mike       ||      hutt       ||      mike@whatever       ||      mike1    ||     1      ||       0       ||

etc.

the login_logs table looks this:

id    ||     login_datetime     || user_id

1     || 2011-01-27 23:04:59 ||      1

2     || 2010-01-27 23:04:59 ||      2

etc.

so login_logs table keeps record of when user has logged in.

now want make query selects inactive users. inactive users are:

1) users have not logged in 90 days

2) users have never logged in

i have made query satisfies first condition not correct:

 select distinct u.id, u.last_name, u.first_name, u.email,u.username   users u inner join login_logs l on l.user_id = u.id    u.activated = 1 , u.suspended = 0  , datediff(curdate(), l.login_datetime) <= 90   order u.last_name, u.first_name, u.id 

the above query not right because if have logged in ages ago, treats me inactive user because sees logged in ages ago.

so want fix mistake describe above , satisfy second condition (select people have never logged in).

select u.* user u left outer join login l on u.id = l.user_id l.user_id null or datediff(curdate(), l.login_datetime) <= 90 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -