I have following two queries and their out comes are different but what I want is as following:
I have two tables:
Subject:
-subject_id (Primary key)
-about
-details
feedback:
-id (Primary Key)
-subject_id (Foreign key)
-rating
-DateAndTime
Following are the queries and their result in words:
SELECT distinct about, details, subject.subject_id, round(AVG(rating),2) as Rating,
Max(DATE_FORMAT( DateAndTime, '%d-%m-%Y' )) as Date,
Max(TIME_FORMAT( DateAndTime, '%h:%i:%s' )) as Time
FROM `subject` , `feedback`
WHERE subject.Subject_ID = feedback.Subject_ID
GROUP BY about,details,subject_id
ORDER BY DateAndTime DESC
Here in this query the output is unique about,details,subject_id column and average rating. But Problem is with date and time. I want the last date and time entered for that result and result also contains that but it isn't in ordered manner.
above query's image
When i perform this query it gives perfect order but the rating gets revised
SELECT distinct about, details, subject.subject_id, round(AVG(rating),2) as Rating,
Max(DATE_FORMAT( DateAndTime, '%d-%m-%Y' )) as Date,
Max(TIME_FORMAT( DateAndTime, '%h:%i:%s' )) as Time
FROM `subject` , `feedback`
WHERE subject.Subject_ID = feedback.Subject_ID
GROUP BY about,details,subject_id,dateandtime
ORDER BY DateAndTime,Time DESC
The difference is just in group by clause.
So anyone could help me please.