There are two tables, table_firm и table_update . It is necessary to select firms from the table_firm table by their last activity contained in the table / field table_update.dateupdate . Table structures:

 table_firm (id, name_firm) table_update (id, id_firm, dateupdate) 

Where,

 table_firm.id = table_update.id_firm 

dateupdate contains the date in the form 20120212

As a result, you need to display a list of companies from the table_firm table so that companies with the smallest number first go to the dateupdate field of the table_update table.

    3 answers 3

    Like so:

     SELECT tr.*, tu.* FROM `table_update` tu JOIN LEFT `table_firm` tr ON tr.id = tu.id_firm ORDER BY tu.dateupdate DESC LIMIT 0, 10 

    LIMIT 0.10 - selects the last 10 lines ... you can not add this entry to the query, then it will display the entire table ...

       select a.name_firm from table_firm a join (select id_firm, max(dateupdate) as upd from table_update group by id_firm) b where a.id = b.id_firm order by b.upd desc; 
         SELECT tf.name_firm FROM table_firm tf, table_update tu WHERE tf.id = tu.id_firm ORDER BY tu.date_update DESC 

        What type date_update field?)

        • field dateupdate bigint - feodul
        • what is the date stored so?) in my script, you can still add a distinct. - namak