我有两个表tbl_user和tbl_lastchangepassword,如下所示
表tbl_user
id| name
---------
1 | user1
2 | user2
3 | user3
表tbl_lastchangepassword
id | loginid | date_password
----------------------------
1 | 1 | 2014-03-29
上表的关系(tbl_user.id = tbl_lastchangepassword.loginid)
如何获得输出
id | name| date_password
---------------------
1 |user1 | 2014-03-29
2 |user2 | null
3 |user3 | null
谢谢。
答案 0 :(得分:2)
试试这个
SELECT U.id,U.name,P.date_password FROM tbl_user U
LEFT JOIN tbl_lastchangepassword P ON U.id= P.loginid
答案 1 :(得分:1)
试试这个
Select a.id, a.name, b.date_password from tbl_user As a
left join tbl_lastchangepassword As b on a.id = b.loginid
OR
Select a.id, a.name,
( select b.date_password from tbl_lastchangepassword As b where b.loginid = a.Id) As date_password
from tbl_user As a