Query using INNER JOIN with problem

1

I am doing a query using INNER JOIN , but when I do the JOIN in the A table with the B and there is no id in the B table, it returns me an array empty. I would like it if it did not find the id in the B table to return the A table anyway or both but with the blank fields in the B table. I'm using the following code:

SELECT *
FROM projects AS p
INNER JOIN project_images AS img ON p.id = img.project_id
WHERE p.id = 44
LIMIT 1
    
asked by anonymous 23.04.2014 / 00:28

2 answers

3

Change INNER JOIN to LEFT JOIN .

    
23.04.2014 / 00:41
0

Complementing @Rodrigo Rigotti's answer

INNER JOIN returns records of two tables, for example A and B, when a record with ID in A equals a record with foreign ID in B. Example

... A INNER JOIN B ON A.ID = B.ID_A ...

will only return records that match on both tables.

LEFT JOIN will return ALL the records in the table to the left of the test. Then if:

... A LEFT JOIN B ON A.ID = B.ID_A ...

will return all records of A, for those where B has the ID_A that matches, the fields of B will be filled with this record, for those where ID_A does not exist that matches, the fields of B will be null.

    
23.12.2015 / 13:18