0

I am trying this from last 2 hours and used many methods like MIN(), DISTINCT and CONCAT() but couldn't able to get my desired result. Need an expert to take a look at my code and tell me where i am doing wrong.

My Database Structure is


ID  | message_security_code | employer_ID | seeker_ID | chat_message  | sent_by  | dated
---------------------------------------------------------------------------------------------
1   | 66666666              |  45         |  78       |  hello        | employer | 2017-05-23
2   | 44444444              |  45         |  78       |  hello        | seeker   | 2017-05-23
3   | 55555555              |  45         |  78       |  hello        | employer | 2017-05-23
4   | 66666666              |  45         |  78       |  hello        | employer | 2017-05-23

I want to fetch all results but only one record will show if the message_security_code the latest one order by ID also where employer_ID = my given id

this is what i am trying from few last hours

TRY 1

"SELECT DISTINCT message_security_code FROM pp_chat_messages WHERE employer_ID = '$id'"

TRY 2

"SELECT MIN(ID) AS ID, employer_ID, seeker_ID, chat_message, sent_by, dated FROM pp_chat_messages WHERE employer_ID = '$id' GROUP BY message_security_code"

Expected Result : if the employer_ID is 45

ID  | message_security_code | employer_ID | seeker_ID | chat_message
----------------------------------------------------------------------
1   | 66666666              |  45         |  78       |  hello
2   | 44444444              |  45         |  78       |  hello
3   | 55555555              |  45         |  78       |  hello
Rohit Poonia
  • 77
  • 1
  • 7

0 Answers0