I have two tables, a message table and a log table.
I want to return all rows in the message table that have been logged to a user and whose message # is greater than a passed parameter.
What I have is:
SELECT * FROM message WHERE id IN ( SELECT msg_id AS id FROM msg_log WHERE user_num='1000' AND msg_id >='1660192')
This query returns nothing, produces no errors, it simply times out… It doesn’t matter if it run from a PHP script or phpMyAdmin. In fact, if run from phpMyAdmin it doesn’t even show the query is running, but it doesn’t allow you to execute another query.
If I break out the IN select
SELECT msg_id AS id FROM msg_log WHERE user_num='1000' AND msg_id >='1660192')
This returns 0 records (as it should)
How do I fix this problem?
Try this:
The
INNER JOINsyntax should be faster thanINclause.Naturally you could speed query up having
INDEXorPRIMARY_KEYINDEXand probably related to message.id with aFOREIGN_KEY