मैं दो मैसेजिंग सिस्टम पर उपयोगकर्ताओं की जानकारी के साथ एक मैसेजिंग सिस्टम पर काम कर रहा हूं।
एक बातचीत 2 या अधिक उपयोगकर्ताओं के बीच हो सकती है। प्रत्येक वार्तालाप में यूआईडी होती है और उपयोगकर्ताओं के बीच आदान-प्रदान किए गए प्रत्येक संदेश को उस वार्तालाप यूआईडी के साथ लेबल किया जाता है।संदेश भेजने के लिए मैसेजिंग सिस्टम क्वेरी, अपठित संदेशों की संख्या और बातचीत में उपयोगकर्ताओं की सरणी
यहाँ टेबल हैं:
conversation_list
: इस तालिका में प्रत्येक पंक्ति user_id
और conversation_id
लिंक, यह भी उपयोगकर्ता द्वारा पिछली बार बातचीत देखी हैं।
`id` -> unique ID, autoincremented
`user_id` -> This contains the user associated with the conversation.
`conversation_id` -> This contains the UID of the conversation
`date_lastView` -> This field has the time that the user viewed the conversation last
conversation_messages
: इस तालिका में प्रत्येक पंक्ति संदेश
`id` -> unique ID, autoincremented
`user_id` -> This contains the user that sent the message.
`conversation_id` -> This contains the UID of the conversation
`date_created` -> This contains the time when the message was posted
`message` -> This contains the message
users
शामिल हैं: इस तालिका में प्रत्येक पंक्ति एक उपयोगकर्ता
`User_ID` -> UID of the user
`FirstName` -> This contains the first name of the user
`LastName` -> This contains the last name of the user
शामिल
मैं पहले से ही प्राप्त करने के लिए एक SQL क्वेरी है हर वार्तालाप का अंतिम संदेश। संदेश यह है:
SELECT *
FROM conversation_messages AS m
JOIN
(SELECT mx.conversation_id,
MAX(mx.date_created) AS MaxTime
FROM conversation_messages AS mx
GROUP BY mx.conversation_id) AS mx ON m.conversation_id = mx.conversation_id
AND m.date_created = mx.MaxTime
JOIN
(SELECT mu.conversation_id
FROM conversation_list AS mu
WHERE mu.user_id = :USER_ID_CONNECTED
GROUP BY mu.conversation_id) AS mux ON m.conversation_id = mux.conversation_id
JOIN conversation_list AS mu ON m.conversation_id = mu.conversation_id
GROUP BY mu.conversation_id
ORDER BY m.date_created DESC
मैं अब इस पूरी तरह से काम कर रहे क्वेरी करने के लिए वापस करने की क्षमता जोड़ना चाहते हैं:
- प्रत्येक बातचीत के लिए बिना पढ़े संदेशों को (
date_creaded
बड़ा के साथ सभी संदेशों की गिनती उपयोगकर्ता में लॉग इनdate_lastView
) - प्रत्येक एरे में प्रत्येक उपयोगकर्ता के
User_ID
युक्त एक सरणी और जब उन्होंने वार्तालाप में एक संदेश पोस्ट किया था तब क्रमबद्ध किया गया। - अंतिम सरणी के समान विचार के साथ लेकिन उपयोगकर्ता के
FirstName
औरLastName
के साथ।
मैंने कुछ चीजों की कोशिश की लेकिन मैं वास्तव में असफल रहा, इसलिए अब मैं एसओ समुदाय को इसकी बहुमूल्य मदद के लिए पूछ रहा हूं। ।
यह सब कर सकते हैं केवल प्रदर्शन बातचीत जहां उपयोगकर्ता के प्रवेश में भाग लेता है
यह मदद करता है, मैं उपयोगकर्ता की बातचीत में बनाई गई एक SQLFiddle
एक अच्छी तरह से लिखा प्रश्न +1 वापस आ जाएगी। – Ben
पहेली के लिए एक और +1। – JStead