I'm trying to make select query in Postgres using LEFT JOIN but I can't get proper results. I have 2 tables - offers and images and when offers have images, they are inserted in table images. But not all offers have images.
Now, I want to select all offers (both with images and without images) from what is searched and if these offers have images, to show them. I tried using LEFT JOIN to select from images if there are images, but when I'm trying to display them, there are NULL values - without any returned values.
What's wrong with my query?
$sql->query("SELECT count(offers.id) as offers_count FROM offers LEFT JOIN images ON images.offer_id = offers.id AND images.file_type = 3 WHERE $where"); //$where is what is searched from user
$SQL = "SELECT images.filename, * FROM offers LEFT JOIN images ON images.offer_id = offers.id AND images.file_type = 3 WHERE $where $result LIMIT 12 OFFSET ".($page-1)*12);
for ($i=0; $i<$sql->getNumRows(); $i++) {
$obj = $sql->getRow($i);
offers::show_offer($obj);
}
function show_offer($offer_obj) {
$img = $offer_obj['filename'];
$picture = '<img src="/'.$img.'" />';
echo '<div>';
echo $picture;
//some other info I show
echo '</div>';
}
select table1.col1, *works in Postgres. I believe it is an error Oracle, did you mean that?insert into) statements and the result you get (as formatted text) including the real statement that is executed.