tbl_marketing
db_maid db_date db_customer
1 01-04-2017 xxxx
2 05-04-2017 lll
3 08-04-2017 ggg
tbl_phonecall
db_id db_mid db_due db_nextdate db_pnote
1 2 15-04-2017 16-04-2017 cccc
2 2 17-04-2017 18-04-2017 bbb
3 1 04-05-2017 16-05-2017 ghghh
this my query
select
select
marketing.*,
phonecall.db_id,
max(phonecall.db_due) db_due,
max(phonecall.db_nextdate) db_nextdate,
phonecall.db_pnote
from tbl_marketing marketing
left outer join tbl_phonecall phonecall
on
phonecall.db_mid=marketing.db_maid
group by marketing.db_maid
The result i want is all rows from tbl_marketing
even if there are Null values exists in the tbl_phonecall BUT NO DUPLICATE RECORDS with the last row from tbl_phoencall
form the db_pnote,db_due associate to row in tbl_marketing
order by the db_due from tbl_phonecall
My query didn't give me the exact result i want
the output will be like that
# Date Customer dueDate NextDate pNote
2 05-04-2017 lll 17-04-2017 18-04-2017 bbbb
1 01-04-2017 xxxx 04-05-2017 16-05-2017 ccc
3 08-04-2017 ggg ghghh