Mysql not returning result as expected
Can anyone see what is wrong with this sql query.
This returns no results, although the same query out put so that vars are calculated and then run in mysql returns 3800+ results
$query = "SELECT * FROM twitter_user JOIN twitter_connection
ON (twitter_user.tu_id = twitter_connection.tc_tu_id)
WHERE tc_followyou = 1 AND tc_twitterapp_user_id = ". $mytwitterid . "
LIMIT " . $perpage . " OFFSET " . $twitter_offset;
This same query however does work
$query = "SELECT * FROM twitter_user JOIN twitter_connection
ON (twitter_user.tu_id = twitter_connection.tc_tu_id)
WHERE tc_youfollow = 1 AND tc_twitterapp_user_id = ". $mytwitterid . "
LIMIT " . $perpage . " OFFSET " . $twitter_offset;
The only difference is the use 开发者_运维技巧of tc_followyou vs tc_youfollow
Both are in the same table, no NULL records, and integer.
If I take the exact same piece of php code adn swap tc_followyou for tc_youfollow I get a result.
I am not sure why, but this is only a problem if the script is run on an amazon RDS server Mysql v5.5.8-log, another server running mysql 5.1.52
works as expected.
Why would either the server version or the field name cause this issue?
I'm stumped.
Thanks Stephen
UPDATE : This is resolved. The issue was that the actual code I was running did not have a limit. I was carelessly running against the database to get a 'total'. This because the failing table had so many records, it did not return a result. I accepted the solution because the person helped me work through a thought process that helped discover the problem.
LIMIT
is unreliable if you don't use ORDER BY
to provide a deterministic sort order. By design, the order of result rows is arbitrary unless you instruct SQL to sort them. That can specially affect the returned rows when you use a LIMIT clause.
精彩评论