SELECT * FROM discussion_comments GROUP BY disc_id ORDER BY posted_date DESC
I have table example
like given below:
CREATE TABLE example
(
id int(11),
cname varchar(11),
posted_date date,
posted_time varchar(20)
);
with values like:
INSERT INTO example
VALUES (1,'abc','2015-03-26','04:25 PM');
INSERT INTO example
VALUES (1,'def','2015-03-27','04:30 PM');
INSERT INTO example
VALUES (2,'ghi','2015-03-11','02:25 AM');
INSERT INTO example
VALUES (2,'jkl','2015-03-15','12:25 PM');
and I am trying to get only the latest value added to the table for an id based on posted_date & posted_time fields.
The result I am trying to achieve is:
(1,'def','2015-03-27','04:30 PM')
(2,'jkl','2015-03-15','12:25 PM')
The query I tried is as follows:
SELECT * FROM `example GROUP BY id ORDER BY posted_date DESC
I am not getting the desired result. Where did I go wrong??
Aucun commentaire:
Enregistrer un commentaire