Please help us we have trouble to get the last recently added distinct row from one of our mysql table and the query includes a cross join too
The scenario is a feedback table and queried every 30 seconds to reply them back. we need to get the latest distinct rows for glancing.
TABLE_1 - PK = id
id | name
1 | Jhon
2 | Smith
TABLE_2 - Composite = stamp,id
stamp | id | feed | feed_for
1467898676 | 1 | hi | 2
1467898678 | 1 | welcome | 2
1467898679 | 2 | hello | 1
1467898680 | 2 | am intrested in your product | 1
now we only need the distinct rows from table_2 and the latest one the join we peformed is as shown
select a.id,a.name,b.stamp,b.feed
from TABLE_1 a, TABLE_2 b
where b.feed_for=2 and a.id=b.id
group by a.id
order by b.stamp desc
It gets unique rows but not the latest one. Please help what would be a efficient and working query
the query i have posted is the fastest one for us(tested on a 2.9 million row table) takes 0.013 secs and its about joining two table while getting unique latest row from one table and joining to get other infos on other table