1

I have two tables tbl_user and tbl_lastchangepassword as shown below

Table tbl_user

id|  name 
---------
1 | user1 
2 | user2 
3 | user3

Table tbl_lastchangepassword

id | loginid | date_password
----------------------------
1  |    1    |  2014-03-29

Relation of Above table (tbl_user.id = tbl_lastchangepassword.loginid)

How do I get output as

id | name| date_password
---------------------
1  |user1 | 2014-03-29 
2  |user2 | null
3  |user3 | null

Thank you.

1
  • Can you put up an example on sqlfiddle.com ? Commented Mar 29, 2014 at 8:44

2 Answers 2

2

Try this

SELECT U.id,U.name,P.date_password FROM tbl_user U 
LEFT JOIN tbl_lastchangepassword P ON U.id= P.loginid
Sign up to request clarification or add additional context in comments.

Comments

1

Try this

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.