Forum Moderators: open
SELECT table_A.id, username, folder, status, postdate, sender, subject, message, table_B.image
FROM table_A
LEFT JOIN table_B
ON table_B.id = table_A.id
WHERE username='example' AND folder='inbox'
# this is actually all of the possible values for status, so I tested with and without this line
AND (status = "New" OR status = "" OR status IS NULL)
AND COALESCE(table_B.sorter,0) = 0
ORDER BY POSTDATE DESC
LIMIT 21
# offset is there because I paginate
OFFSET 0
# I also tried this, but it was no different:
SELECT table_A.id, username, folder, status, postdate, sender, subject, message, table_B.image
FROM table_A
LEFT JOIN table_B
ON table_B.id = table_A.id
AND COALESCE(table_B.sorter,0) = 0
WHERE username='example' AND folder='inbox'
AND (status = "New" OR status = "" OR status IS NULL)
ORDER BY POSTDATE DESC
LIMIT 21
OFFSET 0 table: table_A
type: range
possible_keys: New Messages
# this index is on username, folder, and status
key: New Messages
key_len: 106
key_ref: NULL
rows: 8944
Extra: Using index condition; Using where; Using filesort
table: table_B
type: ref
possible_keys: id_2,ID,View
# this index is on id, sorter, and image; id_2 is on id and sorter, but I used "USE INDEX (id_2)" and it had no impact
key: View
key_len: 4
ref: goncco_forum.private_messages.id
rows: 1
Extra: Using where; Using index Status Duration
Starting 0.000016
Waiting for query cache lock 0.000009
Init 0.000008
Checking query cache for query 0.000022
Checking permissions 0.000008
Opening tables 0.000007
After opening tables 0.000009
Init 0.000014
Optimizing 0.000012
Executing 0.000012
End of update loop 0.000008
Query end 0.000007
Commit 0.000007
Closing tables 0.000007
Starting cleanup 0.000007
Freeing items 0.000008
Updating status 0.000018
Reset for next command 0.000008