Help generate sql query

SELECT DISTINCT news FROM `comments` ORDER BY `id` DESC LIMIT 10 

- it works, but only the news field is selected, and I need id, news, reg, name, comment, date_add

 SELECT DISTINCT news,id,news,reg,name,comment,date_add FROM `comments` ORDER BY `id` DESC LIMIT 10 

- this one doesn't work

    2 answers 2

    DISTINCT is unique in all fields (almost the same as GROUP BY in all fields)

    What you want, you can somehow:

     select `c`.* from ( select `news`, `last` from ( select max( `id` ) `last`, `news` from `comments` group by `news` ) `l` order by `last` desc limit 10 ) `l`, `comments` `c` where `c`.`news` = `l`.`news` and `c`.`id` = `l`.`id` 

      And if so:

       SELECT * FROM comments GROUP BY news ORDER BY id DESC LIMIT 10