从表中多选

时间:2013-08-17 07:02:07

标签: mysql sql

我希望此代码只显示 $ user_id 的朋友,但我想显示朋友的结果和 $ user_id

SELECT *
FROM
  activity,
  friends
WHERE
  friends.user_id='$user_id'
  and activity.activity_user=friends.fr_id
ORDER BY activity.id DESC
LIMIT 10

1 个答案:

答案 0 :(得分:0)

使用JOIN

SELECT
  t1.*
FROM
  activity as t1
  join friends on t1.activity_user=friends.fr_id
WHERE
  friends.user_id='$user_id'
ORDER BY t1.id DESC
LIMIT 10