[Solved] SQL query required [duplicate]
I got an answer and that seems the best way for me. It is having a sub query,but i don’t see a way to avoid that. select t2.state,t1.name,t2.powerconsumption FROM table1 t1 JOIN table2 t2 ON t1.companyid =t2.companyid where t2.powerconsumption =(select MAX(t3.powerconsumption) from table2 t3 where t3.state=t2.state and t3.month=”jan”) SQL Fiddle solved SQL query required [duplicate]