If you have a complicated query that uses many tables but that doesn't return any rows, you should use the following procedure to find out what is wrong:
- Test the query with - EXPLAINto check whether you can find something that is obviously wrong. See Section 12.8.2, “- EXPLAINSyntax”.
- Select only those columns that are used in the - WHEREclause.
- Remove one table at a time from the query until it returns some rows. If the tables are large, it is a good idea to use - LIMIT 10with the query.
- Issue a - SELECTfor the column that should have matched a row against the table that was last removed from the query.
- If you are comparing - FLOATor- DOUBLEcolumns with numbers that have decimals, you can't use equality (- =) comparisons. This problem is common in most computer languages because not all floating-point values can be stored with exact precision. In some cases, changing the- FLOATto a- DOUBLEfixes this. See Section C.5.5.8, “Problems with Floating-Point Values”.
- If you still can't figure out what is wrong, create a minimal test that can be run with - mysql test < query.sqlthat shows your problems. You can create a test file by dumping the tables with mysqldump --quick db_name- tbl_name_1...- tbl_name_n> query.sql. Open the file in an editor, remove some insert lines (if there are more than needed to demonstrate the problem), and add your- SELECTstatement at the end of the file.- Verify that the test file demonstrates the problem by executing these commands: - shell> - mysqladmin create test2shell>- mysql test2 < query.sql- Attach the test file to a bug report, which you can file using the instructions in Section 1.7, “How to Report Bugs or Problems”.