项目中,用到了,多个表查询:
1.使用inner join on
两个表:select * from t_article ta inner join t_user tu on ta.user_id = tu.id;
多个表:select * from (t_article ta inner join t_user tu on ta.user_id = tu.id) inner join t_city tc on tc.user_id = tu.id;
2.使用left join on ,以左表为主
两个表:select * from t_comment tc left join t_article ta on tc.article_id = ta.id; 一个文章有多条评论
三个表:select * from t_comment tc left join t_article ta on tc.article_id = ta.id left join t_user tu on tc.user_id = tu.id;
3.使用right join on
使用方法,与left join on 相同;只不过以右表为主;