Getting Data from multiple tables SQLite

前端 未结 2 1100
甜味超标
甜味超标 2021-01-29 02:21

I have an android application that has 2 tables, one table stores posts and the other table stores images of the posts incase it has an image, changes are not all posts will hav

2条回答
  •  粉色の甜心
    2021-01-29 02:47

    ok, you asked, so give this a whirl, see if you like the output

    SELECT pt.post_id, pt.post, pt.post_description, im.imagePath 
    FROM PostTable pt
    left join ImageTable im
    on im.fk_postID=pt.post_id
    

    It will bring along for the ride the right table (ImageTable) of those posts that don't have images.

    Uses table aliases (pt and im). That helps to be explicit which table the columns come from on the first line in case there are common column names in both, plus a little less typing.

    Untested

    reference Mysql Left Joins

提交回复
热议问题