Ben Za Ben Za - 1 year ago 40
MySQL Question

How can I get the most recent result from a table with a column that has multiple of the same values

I'm trying to get make my table get only 1 of the results that I have in the table. My table stores a posted_by column that allows more than 1 user to post more than once. So, my posted_by column has multiple of the username Chowderrunnah because that user has posted more than once. I only want to display one of the results so each user can be clicked on in the table instead of displaying many of the same user. (I'm trying to create a support ticket system if you're wondering why).

At the moment, my table is getting all the results from my table, even duplicates with the same posted_by (username). I only want it to display one result if there are more than 1 of the same posted by (username).

At the moment, my code is only the minimum -

SELECT * from support WHERE last_post_by != 'Admin'

Help is much appreciated.


Here is the table I'm using Database

Here is my support ticket system

enter image description here

Answer Source

The following Query fixed my problem :)

SELECT * from support WHERE last_post_by != 'Admin' GROUP BY posted_by

Using GROUP BY allowed me to only display one of the duplicate posted_by results.