I'm not sure that what i want to do is actually possible with a single query. The query i've got atm is:
Code SQL:SELECT subject AS subject, message AS message FROM ue_messages RIGHT JOIN ue_messages_delivery ON ue_messages_delivery.recipient_id = '2'
What I want to do is search the table ue_messages_delivery for message ids where the rows matched will be those matching the recipient_id in ue_messages_delivery and then grabbing the messages from the table ue_messages
An example:
ue_messages
message_id subject message
1 Test Subject 1 Test Message 1
2 Test Subject 2 Test Message 2
3 Test Subject 3 Test Message 3
4 Test Subject 4 Test Message 4
ue_messages_delivery
delivery_id message_id sender_id recipient_id date_sent message_read
6 3 3 3 0000-00-00 00:00:00 0
37 1 1 2 0000-00-00 00:00:00 0
38 2 1 2 0000-00-00 00:00:00 0
39 3 1 2 0000-00-00 00:00:00 0
40 4 1 2 0000-00-00 00:00:00 0
41 5 1 2 0000-00-00 00:00:00 0
42 6 1 2 0000-00-00 00:00:00 0
For example:
ue_messages_delivery searched for all messages for recipient number 2, it would get message ids 37, 38, 39, 41, 42 and them messages would be fetched.
If ue_messages_delivery searched for all messages for recipient number 3, it would get message id 6 and only that message would be fetched.
This will be used in a php app so if i can't do it in one query then i'll have to deal with two seperate queries.
The two tables are:
ue_messages
Table comments: Messages Table (Stores all PMs); InnoDB free: 10240 kB
Field Type Null Default Comments
message_id int(11) No
subject text No
message text No
ue_messages_delivery
Table comments: Message Delivery Table; InnoDB free: 10240 kB
Field Type Null Default Comments
delivery_id int(11) No
message_id int(11) No
sender_id int(11) No
recipient_id int(11) No
date_sent datetime No
message_read tinyint(1) No





. At least i was thinking along the right lines but i guess i'll need to read up more on join querys (this is my first time using join querues).





Bookmarks