caner taşdemir caner taşdemir - 2 months ago 6
MySQL Question

mySQL - Don't fetch posts multiple times if it the have same value in a spesific row

I am getting posts using;

SELECT * from posts order by id DESC limit 3


Table structure is;

ID | content | author | date



The problem is, it also fetches posts which have same value in content row.

Result

1- New cars in Oklahoma
2- New cars in Washington
3- New cars in Oklahoma


Now, lets say some posts have exactly same values in content row, how can I fetch these post only 1 time, so that it fetches like

1- New cars in Oklahoma
2- New cars in Washington

Answer

Assuming you're fine with skipped some rows (since they are repeated):

SELECT * from posts group by `content` order by id DESC limit 3

This will show group all rows that contain the same content.