I am trying to get all user information data that is on the USER table and also only the user’s last login information(which is on another table called LOGIN_HISTORY).
I tried with Left join but MySQL is giving me the error which shows "
Expression #15 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'login_history.user_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by"
Here is the USER table
Please help! and this is my LOGIN_HISTORY table.
The output which I want is
I have tried this query, I don’t know what I am missing but it is not giving me the desired output. I only want all the user information with his LAST login_datetime column. I tried the below query but it is showing all the user records with duplicate and all the login_datetime.
select u.id, u.firstname, u.lastname, u.email, u.username, u.password, lh.login_datetime from user u left join login_history lh on u.id = lh.user_id group by u.id order by DATE(lh.login_history) desc;`