MySQL多表联合查询案例

MySQL查询案例------多表联合查询与子查询

问题描述:

        数据库中存在三张表(t_recommend_type_series、t_vod_combine 、t_series),现在三表通过t_vod_combine主键id字段和其他两表中combineId查询出所需要的数据。查出来的数据要求:分页查询t_recommend_type_series中全部字段和Name、TvPosterUrl1字段,过滤数据条件t_recommend_type_series表中字段tagType ,t_vod_combin表字段.programTyp,t_series要求获取TvPosterUrl1是通过字段Status = 0,且要求通过cpsort 降序,Bcharging 升序,addTime 升序后去第一条记录。

问题分析:

SELECT * FROM (
SELECT a.*,ts.Name,ts.TvPosterUrl1 AS image FROM (
	SELECT rts.*,vc.title FROM t_recommend_type_series rts 
	LEFT JOIN t_vod_combine vc ON rts.combineId=vc.id 
	WHERE rts.tagType = 'tagpool' AND vc.programType = 'anime' 
	ORDER BY rts.sort ASC LIMIT 0,50
) a LEFT JOIN t_series ts ON a.combineId = ts.combineId 
WHERE ts.Status = 0
ORDER BY ts.cpsort DESC,ts.Bcharging ASC,ts.addTime ASC) b 
GROUP BY b.id ORDER BY b.sort

你可能感兴趣的:(MySQL多表联合查询案例)