dpb_4431
2017-08-07 02:25从左连接返回mysql查询中的最后一行
I am trying to get the last row of table2 that I left join with table1.
Table1 column:
- id
- name
- created date
Table2 column:
- id
- last_login
- ip_address
Login data stored into table2 everytime user logged in. So I am trying to display all users from table1 which is displaying the last_login
record from table2.
Here is my current query :
SELECT table1.*, table2.last_login
FROM table1
LEFT JOIN table2 ON table2.id= table1.id
ORDER BY table2.last_login desc;
With the query above I am able to get all the data from both table, where if user A logged 5 times, the query will return 5 rows, but I wanted to only showing the user details and their last_login
data. If I add GROUP BY table1.id
it return 1 row record for every user but the last_login
data is not showing the latest record.
- 点赞
- 回答
- 收藏
- 复制链接分享
2条回答
为你推荐
- Mysql Many to Many with Mapping表返回一行并连接会导致重复行的值
- mysql
- php
- concatenation
- 1个回答
- MySQL连接,从一个表返回1行,从另一个表返回多行作为数组或列表
- mysql
- join
- php
- 1个回答
- JDBC工具类连接时的问题
- java
- mysql
- 1个回答
- 从左连接返回mysql查询中的最后一行
- mysql
- join
- php
- 2个回答
- 急求 使用代理出现类型转换异常!!!
- dao
- 0个回答
换一换