php - Mysql - How to retrieve fields from two tables based on certain criteria? -
i trying retrieve post_id, post_year, post_desc, post_title, post_date 1 table , img_filename table post_id equal , is_thumb 1 (where have chosen image posts thumbnail)
this far have got without luck:
select post_id, post_year, post_desc, post_title, post_date, mjbox_posts join mjbox_images using (img_is_thumb) img_is_thumb = 1 , mjbox_images.post_id = mjbox_posts.post_id
thanks
select p.post_id, post_year, post_desc, post_title, post_date, img_filename mjbox_posts p join mjbox_images on i.post_id = p.post_id , i.img_is_thumb = 1
or, if prefer using
syntax,
select post_id, post_year, post_desc, post_title, post_date, img_filename mjbox_posts p join mjbox_images using (post_id) i.img_is_thumb = 1
the difference first query returns post_id
both tables , need alias it.
Comments
Post a Comment