Skip to content

MySQL query result does not return some rows that should be in the result

This is a query that should return a match result of a lost item that has been found. According to my database below, I expect it to return two rows, but only one row is returned. Before I added the second rows in tbl_lost_items and tbl_found_items the result was an empty set.

This is the result

These are my tables

tbl_users

tbl_found_items

tbl_item_types

tbl_lost_items

Also, when I delete a row in tbl_lost_items and tbl_found_items that should return a match, but does not appear in the query result, and then re-enter the same information again in those two tables the result includes a match, but then if there is a new record inserted in tables tbl_lost_items and tbl_found_items that should result in a match the match does not appear in the query result. I can’t figure out what the problem is here. Is this a bug in MySQL? I’m using MySQL 8.0.16 on a mac.

Advertisement

Answer

join don’t match .. in this case use left join

could be some of your values don’t match be sure you have not hiddden chars using TRIM()

User contributions licensed under: CC BY-SA
8 People found this is helpful