I have 3 queries which I want to merge in one with the help of joins but it is not showing right result
from two tables I am taking data in which consphoneno
is common, so one table has more than one row in which thre is a column tstime
which is store current time of data saved so I want to select the latest row from that table and other table is having only row so from there I can fetch data the issue is when I am puting order by to get limit it gives wrong result
what I have done is
individually the three queries are
select consphoneno,billamt,cashbackamt,billno,businessname from cashbackdispdets a where consphoneno='8126815643' order by tstime desc limit 1
select sum(billamt) billamtTotal,sum(cashbackamt) cashbackamtTotal from cashbackdispdets where consphoneno ='8126815643'
select curyearpurchasedamt,curyearcashbackamt from cashbackdisp where consphoneno='8126815643'
What I have done is
select a.consphoneno,a.billamt,a.cashbackamt,a.billno,a.businessname, sum(a.billamt) billamtTotal,sum(a.cashbackamt) cashbackamtTotal,
b.curyearpurchasedamt,b.curyearcashbackamt from cashbackdispdets a,cashbackdisp b where a.consphoneno='8126815643' order by a.tstime desc limit 1
Please check third Image where I am getting wrong result
I want to getlatest row from table one but it is taking first one only