1

i have two tables:

users{user_id, username, picture}
likes{id, user_id, image_id}

the query im trying to do is:

select username, picture
from user and from likes
where user_id=user_id
and image_id=4

but i dnt know how to connect them, thanks

Raidri
  • 17,258
  • 9
  • 62
  • 65
getaway
  • 8,792
  • 22
  • 64
  • 94

1 Answers1

3

The key is to use an INNER JOIN between the two tables.

SELECT u.username, u.picture
    FROM user u
        INNER JOIN likes l
            ON u.user_id = l.user_id
    WHERE l.image_id = 4
Joe Stefanelli
  • 132,803
  • 19
  • 237
  • 235