I am not good in sql so please don’t scold me for such basic question. Currently I am doing a lot of homework on other technologies so I will improve sql as and when I get time to study it. Anyway let come to the point.
My question is for below query. I am trying to fetch data from three tables and it works fine as long as all conditions are satisfied but the problem is that for a posting it may happen that images are not present i.e not record for a posting in image table then post.post_id = img.post_id and img.sequence='1' condition fails and no row is returned but I want row to be returned even if no record present in images for the posting. In such case return null for image path column.
SELECT
img.path as path, pav.value_text as beds, post.post_id as postID
FROM
postings post, post_attributes_values pav, images img
where
post.post_id = pav.post_id and post.status !='expired' and pav.attr_id='33' and post.post_id = img.post_id and img.sequence='1' and post.post_id=49
If all condition satisfies then O/P comes like
path beds postId
-----------------------------------------------
saome path value 2 49
but if post.post_id = img.post_id and img.sequence='1' condition not satisfied then O/P should be like:
path beds postId
----------------------------------------
null 2 49
Use left outer join