需要查询帮助
我有下表。它存储每个用户在聊天中发送和接收的消息。我想选择用户已发送和接收的所有消息并检索它们。然后我可以根据 JQUERY 中的对话 ID 对它们进行排序。我是否必须为此执行两个查询,或者我可以嵌入一个查询吗?本质上我想做的
SELECT * FROM chatbox WHERE sender=?
and
SELECT * FROM chatbox WHERE receiver=?
只是想尽量避免对结果进行两个查询和两个 while 循环。有人有什么建议吗?
I have the following table. It stores messages that each user has sent and received in chats. I want to select all the messages that a user has sent and received and retrieve them. I can then sort them by their conversation id in JQUERY. Would I have to do two queries for this or can I embed a query? Essentially what I want to do is
SELECT * FROM chatbox WHERE sender=?
and
SELECT * FROM chatbox WHERE receiver=?
I just want to try to avoid having two queries and two while loops for the results. Anyone have any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你可以这样做,也可以使用 MySQL 进行排序:
You can do it like this, and also do the ordering with MySQL too:
您可以在单个查询中完成此操作并进行排序;
You can do it in a single query along with the sorting;