They can use different tables, but they have to refer to the correct associated (joined) field that represents the foreign key. The ItemID column is the unique ID for the items table, and the catSearch select is populated with the unique ID of the categories table. There has to be a joined column in the Items table that identifies the category the product is in that is used to compare against the category id passed from the search.