Skip to content
Advertisement

How to select a photo from the photo table for each post by query in MySQL

I have two table I want to show one photo for every post but when the run query show post for every photo

Photo table :

Post table :

use flowing SQL Query and INNER JOIN but my result show like this :

Result Query after execute :

I have 6 posts in post table and I want to get one photo for every post but my result show post by photo count

Advertisement

Answer

You can use group by. Since you have not defined, which photo to use in case of multiple photos for a post, we can get Max() photo for a post:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement