I want to take some records from two tables (products, categories) and actually retrieve the category name from the categories table according to the category id in the products table. The categories table, however, also has a field (COMID) other than the foreign key (CODEID) to the products table, so I want to retrieve the categories where that other field has a specific value.
So, I wrote the following two queries, which both work, and produce the exact same results, where the only difference is the placement of the condition of that other field... In the first case I put it in the general WHERE clause, whereas in the second case I put it in the ON clause of the INNER JOIN part of the query...
$sql = 'SELECT prod.DESCRIPTION, cat1.DESCR, prod.ICTID, prod.IGSID, prod.IGPID
FROM MATERIAL AS prod
INNER JOIN ITEMCATEGORY AS cat1 ON cat1.CODEID = prod.ICTID
WHERE prod.ISACTIVE = 1 AND cat1.COMID = 12';
And
$sql = 'SELECT prod.DESCRIPTION, cat1.DESCR, prod.ICTID, prod.IGSID, prod.IGPID
FROM MATERIAL AS prod
INNER JOIN ITEMCATEGORY AS cat1 ON cat1.CODEID = prod.ICTID AND cat1.COMID = 12
WHERE prod.ISACTIVE = 1';
Is there such a thing as a more correct approach in the above situation?
Thanks a lot in advance.