mysql db表查询

时间:2011-02-09 16:39:32

标签: mysql database-table

我有两张桌子:

users{user_id, username, picture}
likes{id, user_id, image_id}
我试图做的查询是:

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

但我知道如何连接它们,谢谢

1 个答案:

答案 0 :(得分:3)

关键是在两个表之间使用INNER JOIN

SELECT u.username, u.picture
    FROM user u
        INNER JOIN likes l
            ON u.user_id = l.user_id
    WHERE l.image_id = 4