I Have "user_chat" table name his 4 columns

"msg_id" Auto Increament
"chat_from_id"
"chat_to_id"
"chat_msgs"

  SELECT `chat_msgs` from `user_chat` where chat_from_id='2'AND chat_to_id='10' LIMIT 0,10 

Also I have used DESC using above queary but not worked

I want to fetch last 5 recent records from "chat_msgs" columns

Suggest me.

Thank you

Recommended Answers

All 5 Replies

try to order the results by the msg_id descending

something like...
select chat_msgs from user_chat where chat_from_id='2' and chat_to_id='10' limit 0,10 order by msg_id desc

@Patrick: its not work i have checked.

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order by msg_id desc' at line 1

my mistake. the limit statement should be at the end of the query.

Try referring to This StackOverflow Question if it is still not working after moving the limit statement.

commented: @Patrick: Thank You +0
SELECT `chat_msgs` from `user_chat` where chat_from_id='2'AND chat_to_id='10' Order by MSG_ID DESC LIMIT 0,5

Above code will show you the 5 most recent chat

Limit 0,10 will gave you the 10 recent chat

Try this query :

select chat_msgs from user_chat where chat_from_id=2 and chat_to_id=10 order by chat_msgs desc limit 5
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.