【发布时间】:2015-08-25 20:48:20
【问题描述】:
所以我有两张桌子。
一个存储用户,名为user:
id date_joined username
1 2014-12-12 UserA
2 2014-11-11 UserB
还有一个存储内容,命名为article:
id user_id date content
1 1 2014-10-10 content here
2 1 2014-11-10 content here
3 2 2014-12-10 content here
4 1 2014-13-10 content here
查询此数据以获取每个用户的用户名以及内容的正确方法是什么?
我目前有这个:
SELECT user.username, article.date, article.content
FROM article
LEFT JOIN user ON user.id = article.user_id
ORDER BY article.date
这可行,但完全是猜测。这是正确的查询吗?我是否需要所有元素中的user. 和article.?还是只为LEFT JOIN 位?
那么这也是正确/推荐的吗?
SELECT username, date, content
FROM article
LEFT JOIN user ON user.id = article.user_id
ORDER BY date
【问题讨论】: